Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8b0d5bc3 authored by The Android Open Source Project's avatar The Android Open Source Project
Browse files

merge from froyo-plus-aosp

Change-Id: I8b8714eef0295bd5d731b3a0ef816392b1c51261
parents d3844bcf f1f33c4e
Loading
Loading
Loading
Loading
+53 −30
Original line number Diff line number Diff line
@@ -496,7 +496,7 @@ public class DateUtils
                }
            }
        } else if (duration < WEEK_IN_MILLIS && minResolution < WEEK_IN_MILLIS) {
            count = duration / DAY_IN_MILLIS;
            count = getNumberOfDaysPassed(time, now);
            if (past) {
                if (abbrevRelative) {
                    resId = com.android.internal.R.plurals.abbrev_num_days_ago;
@@ -520,6 +520,24 @@ public class DateUtils
        return String.format(format, count);
    }
    
    /**
     * Returns the number of days passed between two dates.
     *
     * @param date1 first date
     * @param date2 second date
     * @return number of days passed between to dates.
     */
    private synchronized static long getNumberOfDaysPassed(long date1, long date2) {
        if (sThenTime == null) {
            sThenTime = new Time();
        }
        sThenTime.set(date1);
        int day1 = Time.getJulianDay(date1, sThenTime.gmtoff);
        sThenTime.set(date2);
        int day2 = Time.getJulianDay(date2, sThenTime.gmtoff);
        return Math.abs(day2 - day1);
    }

    /**
     * Return string describing the elapsed time since startTime formatted like
     * "[relative time/date], [time]".
@@ -1550,18 +1568,22 @@ public class DateUtils
    public static CharSequence getRelativeTimeSpanString(Context c, long millis,
            boolean withPreposition) {

        String result;
        long now = System.currentTimeMillis();
        long span = now - millis;

        synchronized (DateUtils.class) {
            if (sNowTime == null) {
                sNowTime = new Time();
            }

            if (sThenTime == null) {
                sThenTime = new Time();
            }

            sNowTime.set(now);
            sThenTime.set(millis);

        String result;
            int prepositionId;
            if (span < DAY_IN_MILLIS && sNowTime.weekDay == sThenTime.weekDay) {
                // Same day
@@ -1585,6 +1607,7 @@ public class DateUtils
                Resources res = c.getResources();
                result = res.getString(prepositionId, result);
            }
        }
        return result;
    }