package com.maxiee.heartbeat.common;

import android.content.Context;
import android.text.format.DateFormat;

import com.maxiee.heartbeat.R;

import java.util.Calendar;

/**
 * Created by maxiee on 15-6-14.
 */
public class TimeUtils {

    private static final int MS_ONE_SEC = 1000;
    private static final int MS_ONE_MIN = 60 * MS_ONE_SEC;
    private static final int MS_ONE_HOUR = MS_ONE_MIN * 60;
    public static final int MS_ONE_DAY = MS_ONE_HOUR * 24;
    private static final int MS_TEN_DAYS = MS_ONE_DAY * 10;

    public static String parseTime(final Context context, final long timestamp) {
        Long timeNow = System.currentTimeMillis();
        Long delta = timeNow - timestamp;

        if (delta > MS_TEN_DAYS) {
            Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis(timestamp);
            return DateFormat.format("yyyy-MM-dd", cal).toString();
        }

        long count = 0;
        String timeUnit = "";

        if (delta < MS_ONE_HOUR) {
            count = delta/ MS_ONE_MIN;
            timeUnit = context.getString(R.string.minute_ago);
        } else if (delta < MS_ONE_DAY) {
            count = delta/ MS_ONE_HOUR;
            timeUnit = context.getString(R.string.hour_ago);
        } else if (delta < MS_TEN_DAYS) {
            count = delta/ MS_ONE_DAY;
            timeUnit = context.getString(R.string.day_ago);
        }
        return String.valueOf(count) + timeUnit;
    }
}

@@ -229,16 +229,60 @@
 Utils %7B%0A
+    private final static int WEEK_COUNT = 7;
 %0A    pri
@@ -1485,11 +1485,793 @@
 t;%0A    %7D
+%0A%0A    public static Calendar calendarDaysBefore(int days) %7B%0A        Calendar curDate = Calendar.getInstance();%0A        curDate.set(%0A                curDate.get(Calendar.YEAR),%0A                curDate.get(Calendar.MONTH),%0A                curDate.get(Calendar.DAY_OF_MONTH),%0A                0, 0%0A        );%0A        curDate.add(Calendar.DAY_OF_MONTH, -1 * days);%0A        return curDate;%0A    %7D%0A%0A    public static String%5B%5D getWeekDateString() %7B%0A        String%5B%5D ret = new String%5BWEEK_COUNT%5D;%0A        Calendar cal = Calendar.getInstance();%0A        cal.add(Calendar.DAY_OF_MONTH, -1 * WEEK_COUNT);%0A        for (int i=0; i%3CWEEK_COUNT; i++) %7B%0A            ret%5Bi%5D = DateFormat.format(%22MM%E6%9C%88dd%E6%97%A5%22, cal).toString();%0A            cal.add(Calendar.DAY_OF_MONTH, 1);%0A        %7D%0A        return ret;%0A    %7D
 %0A%7D%0A

add 2 static methods.