diff options
author | Elliott Hughes <enh@google.com> | 2013-03-07 16:46:55 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-03-07 16:46:55 -0800 |
commit | 5acc6e521494f1ea21c793d0b56667dae107a1be (patch) | |
tree | 9b1688b262aeb54f93ef897abbb982043f776bd5 | |
parent | d0d1be2d27af35fe7553835ee8c411fd13d1c8d7 (diff) | |
download | frameworks_base-5acc6e521494f1ea21c793d0b56667dae107a1be.zip frameworks_base-5acc6e521494f1ea21c793d0b56667dae107a1be.tar.gz frameworks_base-5acc6e521494f1ea21c793d0b56667dae107a1be.tar.bz2 |
Use getRelativeDayString in getRelativeTimeSpanString.
The bug we're fixing here is that languages that don't
distinguish the "one" case grammatically (such as Japanese)
would say the equivalent of "In 1 day" rather than "Tomorrow"
because of the misuse of getQuantityString.
This has the side-effect of switching us over to the CLDR
strings for relative day names, which have consistent capitalization;
the Android donottranslate-cldr.xml strings varied even within
a language, so although this is a change, it seems like a step
in the right direction.
In a future change, we should actually push all relative
day formatting down into icu4c.
Bug: 7098707
Change-Id: Ia2f9af3d18c441d6093dd5da7956a3d0130e5b06
-rw-r--r-- | core/java/android/text/format/DateUtils.java | 50 |
1 files changed, 10 insertions, 40 deletions
diff --git a/core/java/android/text/format/DateUtils.java b/core/java/android/text/format/DateUtils.java index 8920b24..5a20ceb 100644 --- a/core/java/android/text/format/DateUtils.java +++ b/core/java/android/text/format/DateUtils.java @@ -429,20 +429,7 @@ public class DateUtils } } } else if (duration < WEEK_IN_MILLIS && minResolution < WEEK_IN_MILLIS) { - count = getNumberOfDaysPassed(time, now); - if (past) { - if (abbrevRelative) { - resId = com.android.internal.R.plurals.abbrev_num_days_ago; - } else { - resId = com.android.internal.R.plurals.num_days_ago; - } - } else { - if (abbrevRelative) { - resId = com.android.internal.R.plurals.abbrev_in_num_days; - } else { - resId = com.android.internal.R.plurals.in_num_days; - } - } + return getRelativeDayString(r, time, now); } else { // We know that we won't be showing the time, so it is safe to pass // in a null context. @@ -454,24 +441,6 @@ public class DateUtils } /** - * 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]". * <p> @@ -529,28 +498,29 @@ public class DateUtils * today this function returns "Today", if the day was a week ago it returns "7 days ago", and * if the day is in 2 weeks it returns "in 14 days". * - * @param r the resources to get the strings from + * @param r the resources * @param day the relative day to describe in UTC milliseconds * @param today the current time in UTC milliseconds - * @return a formatting string */ private static final String getRelativeDayString(Resources r, long day, long today) { + Locale locale = r.getConfiguration().locale; + if (locale == null) { + locale = Locale.getDefault(); + } + + // TODO: use TimeZone.getOffset instead. Time startTime = new Time(); startTime.set(day); + int startDay = Time.getJulianDay(day, startTime.gmtoff); + Time currentTime = new Time(); currentTime.set(today); - - int startDay = Time.getJulianDay(day, startTime.gmtoff); int currentDay = Time.getJulianDay(today, currentTime.gmtoff); int days = Math.abs(currentDay - startDay); boolean past = (today > day); // TODO: some locales name other days too, such as de_DE's "Vorgestern" (today - 2). - Locale locale = r.getConfiguration().locale; - if (locale == null) { - locale = Locale.getDefault(); - } if (days == 1) { if (past) { return LocaleData.get(locale).yesterday; |