Loading core/java/android/text/format/DateUtils.java +53 −30 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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]". Loading Loading @@ -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 Loading @@ -1585,6 +1607,7 @@ public class DateUtils Resources res = c.getResources(); result = res.getString(prepositionId, result); } } return result; } Loading Loading
core/java/android/text/format/DateUtils.java +53 −30 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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]". Loading Loading @@ -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 Loading @@ -1585,6 +1607,7 @@ public class DateUtils Resources res = c.getResources(); result = res.getString(prepositionId, result); } } return result; } Loading