diff options
4 files changed, 119 insertions, 118 deletions
diff --git a/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java b/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java index 02d8f97..e84c287 100644 --- a/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java +++ b/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java @@ -18,14 +18,14 @@ package benchmarks.regression; import com.google.caliper.SimpleBenchmark; -import java.util.Locale; -import java.util.TimeZone; +import android.icu.util.ULocale; +import android.icu.util.TimeZone; import static libcore.icu.DateIntervalFormat.*; public class DateIntervalFormatBenchmark extends SimpleBenchmark { public void timeDateIntervalFormat_formatDateRange_DATE(int reps) throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY; @@ -35,7 +35,7 @@ public class DateIntervalFormatBenchmark extends SimpleBenchmark { } public void timeDateIntervalFormat_formatDateRange_TIME(int reps) throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); int flags = FORMAT_SHOW_TIME | FORMAT_24HOUR; @@ -45,7 +45,7 @@ public class DateIntervalFormatBenchmark extends SimpleBenchmark { } public void timeDateIntervalFormat_formatDateRange_DATE_TIME(int reps) throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY | FORMAT_SHOW_TIME | FORMAT_24HOUR; diff --git a/luni/src/main/java/libcore/icu/DateIntervalFormat.java b/luni/src/main/java/libcore/icu/DateIntervalFormat.java index 96d2ca7..10e3e6a 100644 --- a/luni/src/main/java/libcore/icu/DateIntervalFormat.java +++ b/luni/src/main/java/libcore/icu/DateIntervalFormat.java @@ -16,9 +16,12 @@ package libcore.icu; +import com.ibm.icu.impl.JavaTimeZone; +import com.ibm.icu.util.Calendar; +import com.ibm.icu.util.GregorianCalendar; +import com.ibm.icu.util.ULocale; + import java.text.FieldPosition; -import java.util.Calendar; -import java.util.Locale; import java.util.TimeZone; import libcore.util.BasicLruCache; @@ -45,9 +48,6 @@ public final class DateIntervalFormat { public static final int FORMAT_NUMERIC_DATE = 0x20000; public static final int FORMAT_ABBREV_ALL = 0x80000; - private static final int DAY_IN_MS = 24 * 60 * 60 * 1000; - private static final int EPOCH_JULIAN_DAY = 2440588; - private static final FormatterCache CACHED_FORMATTERS = new FormatterCache(); static class FormatterCache extends BasicLruCache<String, com.ibm.icu.text.DateIntervalFormat> { @@ -64,23 +64,24 @@ public final class DateIntervalFormat { if ((flags & FORMAT_UTC) != 0) { olsonId = "UTC"; } + // We create a java.util.TimeZone here to use libcore's data and libcore's olson ID / pseudo-tz + // logic. TimeZone tz = (olsonId != null) ? TimeZone.getTimeZone(olsonId) : TimeZone.getDefault(); - return formatDateRange(Locale.getDefault(), tz, startMs, endMs, flags); + com.ibm.icu.util.TimeZone icuTimeZone = icuTimeZone(tz); + ULocale icuLocale = ULocale.getDefault(); + return formatDateRange(icuLocale, icuTimeZone, startMs, endMs, flags); } // This is our slightly more sensible internal API. (A truly sane replacement would take a // skeleton instead of int flags.) - public static String formatDateRange(Locale locale, TimeZone tz, long startMs, long endMs, - int flags) { - Calendar startCalendar = Calendar.getInstance(tz); - startCalendar.setTimeInMillis(startMs); - + public static String formatDateRange(ULocale icuLocale, com.ibm.icu.util.TimeZone icuTimeZone, + long startMs, long endMs, int flags) { + Calendar startCalendar = createIcuCalendar(icuTimeZone, icuLocale, startMs); Calendar endCalendar; if (startMs == endMs) { endCalendar = startCalendar; } else { - endCalendar = Calendar.getInstance(tz); - endCalendar.setTimeInMillis(endMs); + endCalendar = createIcuCalendar(icuTimeZone, icuLocale, endMs); } boolean endsAtMidnight = isMidnight(endCalendar); @@ -92,27 +93,26 @@ public final class DateIntervalFormat { if (startMs != endMs && endsAtMidnight && ((flags & FORMAT_SHOW_TIME) == 0 || dayDistance(startCalendar, endCalendar) <= 1)) { endCalendar.roll(Calendar.DAY_OF_MONTH, false); - endMs -= DAY_IN_MS; } String skeleton = toSkeleton(startCalendar, endCalendar, flags); synchronized (CACHED_FORMATTERS) { - com.ibm.icu.text.DateIntervalFormat formatter = getFormatter(skeleton, locale, tz); - com.ibm.icu.util.Calendar scal = icuCalendar(startCalendar); - com.ibm.icu.util.Calendar ecal = icuCalendar(endCalendar); - return formatter.format(scal, ecal, new StringBuffer(), new FieldPosition(0)).toString(); + com.ibm.icu.text.DateIntervalFormat formatter = + getFormatter(skeleton, icuLocale, icuTimeZone); + return formatter.format(startCalendar, endCalendar, new StringBuffer(), + new FieldPosition(0)).toString(); } } - private static com.ibm.icu.text.DateIntervalFormat getFormatter(String skeleton, Locale locale, - TimeZone tz) { - String key = skeleton + "\t" + locale + "\t" + tz; + private static com.ibm.icu.text.DateIntervalFormat getFormatter(String skeleton, ULocale locale, + com.ibm.icu.util.TimeZone icuTimeZone) { + String key = skeleton + "\t" + locale + "\t" + icuTimeZone; com.ibm.icu.text.DateIntervalFormat formatter = CACHED_FORMATTERS.get(key); if (formatter != null) { return formatter; } formatter = com.ibm.icu.text.DateIntervalFormat.getInstance(skeleton, locale); - formatter.setTimeZone(icuTimeZone(tz)); + formatter.setTimeZone(icuTimeZone); CACHED_FORMATTERS.put(key, formatter); return formatter; } @@ -223,39 +223,30 @@ public final class DateIntervalFormat { } private static boolean isThisYear(Calendar c) { - Calendar now = Calendar.getInstance(c.getTimeZone()); + Calendar now = (Calendar) c.clone(); + now.setTimeInMillis(System.currentTimeMillis()); return c.get(Calendar.YEAR) == now.get(Calendar.YEAR); } - // Return the date difference for the two times in a given timezone. - public static int dayDistance(TimeZone tz, long startTime, long endTime) { - return julianDay(tz, endTime) - julianDay(tz, startTime); - } - public static int dayDistance(Calendar c1, Calendar c2) { - return julianDay(c2) - julianDay(c1); + return c2.get(Calendar.JULIAN_DAY) - c1.get(Calendar.JULIAN_DAY); } - private static int julianDay(TimeZone tz, long time) { - long utcMs = time + tz.getOffset(time); - return (int) (utcMs / DAY_IN_MS) + EPOCH_JULIAN_DAY; + /** + * Creates an immutable ICU timezone backed by the specified libcore timezone data. At the time of + * writing the libcore implementation is faster but restricted to 1902 - 2038. + * Callers must not modify the {@code tz} after calling this method. + */ + static com.ibm.icu.util.TimeZone icuTimeZone(TimeZone tz) { + JavaTimeZone javaTimeZone = new JavaTimeZone(tz, null); + javaTimeZone.freeze(); // Optimization - allows the timezone to be copied cheaply. + return javaTimeZone; } - private static int julianDay(Calendar c) { - long utcMs = c.getTimeInMillis() + c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET); - return (int) (utcMs / DAY_IN_MS) + EPOCH_JULIAN_DAY; + static Calendar createIcuCalendar(com.ibm.icu.util.TimeZone icuTimeZone, ULocale icuLocale, + long timeInMillis) { + Calendar calendar = new GregorianCalendar(icuTimeZone, icuLocale); + calendar.setTimeInMillis(timeInMillis); + return calendar; } - - private static com.ibm.icu.util.TimeZone icuTimeZone(TimeZone tz) { - final int timezoneType = com.ibm.icu.util.TimeZone.TIMEZONE_JDK; - return com.ibm.icu.util.TimeZone.getTimeZone(tz.getID(), timezoneType); - } - - private static com.ibm.icu.util.Calendar icuCalendar(Calendar cal) { - com.ibm.icu.util.TimeZone timeZone = icuTimeZone(cal.getTimeZone()); - com.ibm.icu.util.Calendar result = com.ibm.icu.util.Calendar.getInstance(timeZone); - result.setTime(cal.getTime()); - return result; - } - } diff --git a/luni/src/main/java/libcore/icu/RelativeDateTimeFormatter.java b/luni/src/main/java/libcore/icu/RelativeDateTimeFormatter.java index 750df00..8d62c78 100644 --- a/luni/src/main/java/libcore/icu/RelativeDateTimeFormatter.java +++ b/luni/src/main/java/libcore/icu/RelativeDateTimeFormatter.java @@ -16,13 +16,11 @@ package libcore.icu; -import java.util.Calendar; -import java.util.GregorianCalendar; import java.util.Locale; -import java.util.TimeZone; import libcore.util.BasicLruCache; -import libcore.icu.DateIntervalFormat; + import com.ibm.icu.text.DisplayContext; +import com.ibm.icu.util.Calendar; import com.ibm.icu.util.ULocale; /** @@ -50,6 +48,9 @@ public final class RelativeDateTimeFormatter { // constant comes from public API in DateUtils, it cannot be fixed here. public static final long YEAR_IN_MILLIS = WEEK_IN_MILLIS * 52; + private static final int DAY_IN_MS = 24 * 60 * 60 * 1000; + private static final int EPOCH_JULIAN_DAY = 2440588; + private static final FormatterCache CACHED_FORMATTERS = new FormatterCache(); static class FormatterCache @@ -89,7 +90,7 @@ public final class RelativeDateTimeFormatter { * always // returns a string like '0 seconds/minutes/... ago' according to * minResolution. */ - public static String getRelativeTimeSpanString(Locale locale, TimeZone tz, long time, + public static String getRelativeTimeSpanString(Locale locale, java.util.TimeZone tz, long time, long now, long minResolution, int flags) { if (locale == null) { throw new NullPointerException("locale == null"); @@ -97,6 +98,9 @@ public final class RelativeDateTimeFormatter { if (tz == null) { throw new NullPointerException("tz == null"); } + ULocale icuLocale = ULocale.forLocale(locale); + com.ibm.icu.util.TimeZone icuTimeZone = DateIntervalFormat.icuTimeZone(tz); + long duration = Math.abs(now - time); boolean past = (now >= time); @@ -142,7 +146,7 @@ public final class RelativeDateTimeFormatter { count = (int)(duration / HOUR_IN_MILLIS); unit = com.ibm.icu.text.RelativeDateTimeFormatter.RelativeUnit.HOURS; } else if (duration < WEEK_IN_MILLIS && minResolution < WEEK_IN_MILLIS) { - count = Math.abs(DateIntervalFormat.dayDistance(tz, time, now)); + count = Math.abs(dayDistance(icuTimeZone, time, now)); unit = com.ibm.icu.text.RelativeDateTimeFormatter.RelativeUnit.DAYS; if (count == 2) { @@ -156,14 +160,14 @@ public final class RelativeDateTimeFormatter { String str; if (past) { synchronized (CACHED_FORMATTERS) { - str = getFormatter(locale.toString(), style, capitalizationContext) + str = getFormatter(icuLocale, style, capitalizationContext) .format( com.ibm.icu.text.RelativeDateTimeFormatter.Direction.LAST_2, com.ibm.icu.text.RelativeDateTimeFormatter.AbsoluteUnit.DAY); } } else { synchronized (CACHED_FORMATTERS) { - str = getFormatter(locale.toString(), style, capitalizationContext) + str = getFormatter(icuLocale, style, capitalizationContext) .format( com.ibm.icu.text.RelativeDateTimeFormatter.Direction.NEXT_2, com.ibm.icu.text.RelativeDateTimeFormatter.AbsoluteUnit.DAY); @@ -198,32 +202,28 @@ public final class RelativeDateTimeFormatter { // formatDateRange() would determine that based on the current system // time and may give wrong results. if ((flags & (FORMAT_NO_YEAR | FORMAT_SHOW_YEAR)) == 0) { - Calendar timeCalendar = new GregorianCalendar(false); - timeCalendar.setTimeZone(tz); - timeCalendar.setTimeInMillis(time); - Calendar nowCalendar = new GregorianCalendar(false); - nowCalendar.setTimeZone(tz); - nowCalendar.setTimeInMillis(now); - - if (timeCalendar.get(Calendar.YEAR) != nowCalendar.get(Calendar.YEAR)) { - flags |= FORMAT_SHOW_YEAR; - } else { - flags |= FORMAT_NO_YEAR; - } + Calendar timeCalendar = DateIntervalFormat.createIcuCalendar(icuTimeZone, icuLocale, time); + Calendar nowCalendar = DateIntervalFormat.createIcuCalendar(icuTimeZone, icuLocale, now); + + if (timeCalendar.get(Calendar.YEAR) != nowCalendar.get(Calendar.YEAR)) { + flags |= FORMAT_SHOW_YEAR; + } else { + flags |= FORMAT_NO_YEAR; + } } - return DateIntervalFormat.formatDateRange(locale, tz, time, time, flags); + return DateIntervalFormat.formatDateRange(icuLocale, icuTimeZone, time, time, flags); } if (relative) { synchronized (CACHED_FORMATTERS) { - return getFormatter(locale.toString(), style, capitalizationContext) + return getFormatter(icuLocale, style, capitalizationContext) .format(count, direction, unit); } } else { capitalizationContext = DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE; synchronized (CACHED_FORMATTERS) { - return getFormatter(locale.toString(), style, capitalizationContext) + return getFormatter(icuLocale, style, capitalizationContext) .format(direction, aunit); } } @@ -258,7 +258,7 @@ public final class RelativeDateTimeFormatter { * now - 2 hours, now, HOUR_IN_MILLIS, DAY_IN_MILLIS, 0), instead of '2 * hours ago, 11:30 PM' even with minResolution being HOUR_IN_MILLIS. */ - public static String getRelativeDateTimeString(Locale locale, TimeZone tz, long time, + public static String getRelativeDateTimeString(Locale locale, java.util.TimeZone tz, long time, long now, long minResolution, long transitionResolution, int flags) { if (locale == null) { @@ -267,10 +267,12 @@ public final class RelativeDateTimeFormatter { if (tz == null) { throw new NullPointerException("tz == null"); } + ULocale icuLocale = ULocale.forLocale(locale); + com.ibm.icu.util.TimeZone icuTimeZone = DateIntervalFormat.icuTimeZone(tz); // Get the time clause first. - String timeClause = DateIntervalFormat.formatDateRange(locale, tz, time, time, - FORMAT_SHOW_TIME); + String timeClause = DateIntervalFormat.formatDateRange(icuLocale, icuTimeZone, time, time, + FORMAT_SHOW_TIME); long duration = Math.abs(now - time); // It doesn't make much sense to have results like: "1 week ago, 10:50 AM". @@ -288,12 +290,8 @@ public final class RelativeDateTimeFormatter { // are currently using the _NONE option only. DisplayContext capitalizationContext = DisplayContext.CAPITALIZATION_NONE; - Calendar timeCalendar = new GregorianCalendar(false); - timeCalendar.setTimeZone(tz); - timeCalendar.setTimeInMillis(time); - Calendar nowCalendar = new GregorianCalendar(false); - nowCalendar.setTimeZone(tz); - nowCalendar.setTimeInMillis(now); + Calendar timeCalendar = DateIntervalFormat.createIcuCalendar(icuTimeZone, icuLocale, time); + Calendar nowCalendar = DateIntervalFormat.createIcuCalendar(icuTimeZone, icuLocale, now); int days = Math.abs(DateIntervalFormat.dayDistance(timeCalendar, nowCalendar)); @@ -318,12 +316,12 @@ public final class RelativeDateTimeFormatter { flags = FORMAT_SHOW_DATE | FORMAT_NO_YEAR | FORMAT_ABBREV_MONTH; } - dateClause = DateIntervalFormat.formatDateRange(locale, tz, time, time, flags); + dateClause = DateIntervalFormat.formatDateRange(icuLocale, icuTimeZone, time, time, flags); } // Combine the two clauses, such as '5 days ago, 10:50 AM'. synchronized (CACHED_FORMATTERS) { - return getFormatter(locale.toString(), style, capitalizationContext) + return getFormatter(icuLocale, style, capitalizationContext) .combineDateAndTime(dateClause, timeClause); } } @@ -337,15 +335,26 @@ public final class RelativeDateTimeFormatter { * formatter->action(). */ private static com.ibm.icu.text.RelativeDateTimeFormatter getFormatter( - String localeName, com.ibm.icu.text.RelativeDateTimeFormatter.Style style, + ULocale locale, com.ibm.icu.text.RelativeDateTimeFormatter.Style style, DisplayContext capitalizationContext) { - String key = localeName + "\t" + style + "\t" + capitalizationContext; + String key = locale + "\t" + style + "\t" + capitalizationContext; com.ibm.icu.text.RelativeDateTimeFormatter formatter = CACHED_FORMATTERS.get(key); if (formatter == null) { formatter = com.ibm.icu.text.RelativeDateTimeFormatter.getInstance( - new ULocale(localeName), null, style, capitalizationContext); + locale, null, style, capitalizationContext); CACHED_FORMATTERS.put(key, formatter); } return formatter; } + + // Return the date difference for the two times in a given timezone. + private static int dayDistance(com.ibm.icu.util.TimeZone icuTimeZone, long startTime, + long endTime) { + return julianDay(icuTimeZone, endTime) - julianDay(icuTimeZone, startTime); + } + + private static int julianDay(com.ibm.icu.util.TimeZone icuTimeZone, long time) { + long utcMs = time + icuTimeZone.getOffset(time); + return (int) (utcMs / DAY_IN_MS) + EPOCH_JULIAN_DAY; + } } diff --git a/luni/src/test/java/libcore/icu/DateIntervalFormatTest.java b/luni/src/test/java/libcore/icu/DateIntervalFormatTest.java index d49579c..d14710c 100644 --- a/luni/src/test/java/libcore/icu/DateIntervalFormatTest.java +++ b/luni/src/test/java/libcore/icu/DateIntervalFormatTest.java @@ -16,9 +16,10 @@ package libcore.icu; -import java.util.Calendar; -import java.util.Locale; -import java.util.TimeZone; +import android.icu.util.Calendar; +import android.icu.util.TimeZone; +import android.icu.util.ULocale; + import static libcore.icu.DateIntervalFormat.*; public class DateIntervalFormatTest extends junit.framework.TestCase { @@ -32,7 +33,7 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { public void test_formatDateInterval() throws Exception { TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); - Calendar c = Calendar.getInstance(tz, Locale.US); + Calendar c = Calendar.getInstance(tz, ULocale.US); c.set(Calendar.MONTH, Calendar.JANUARY); c.set(Calendar.DAY_OF_MONTH, 19); c.set(Calendar.HOUR_OF_DAY, 3); @@ -51,10 +52,10 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { long noonDuration = (8 * 60 + 30) * 60 * 1000 - 15 * 1000; long midnightDuration = (3 * 60 + 30) * 60 * 1000 + 15 * 1000; - Locale de_DE = new Locale("de", "DE"); - Locale en_US = new Locale("en", "US"); - Locale es_ES = new Locale("es", "ES"); - Locale es_US = new Locale("es", "US"); + ULocale de_DE = new ULocale("de", "DE"); + ULocale en_US = new ULocale("en", "US"); + ULocale es_ES = new ULocale("es", "ES"); + ULocale es_US = new ULocale("es", "US"); assertEquals("Monday", formatDateRange(en_US, tz, fixedTime, fixedTime + HOUR, FORMAT_SHOW_WEEKDAY)); assertEquals("January 19", formatDateRange(en_US, tz, timeWithCurrentYear, timeWithCurrentYear + HOUR, FORMAT_SHOW_DATE)); @@ -168,7 +169,7 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { // http://b/8862241 - we should be able to format dates past 2038. // See also http://code.google.com/p/android/issues/detail?id=13050. public void test8862241() throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = Calendar.getInstance(tz, l); c.clear(); @@ -182,7 +183,7 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { // http://b/10089890 - we should take the given time zone into account. public void test10089890() throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); TimeZone pacific = TimeZone.getTimeZone("America/Los_Angeles"); int flags = FORMAT_SHOW_DATE | FORMAT_ABBREV_ALL | FORMAT_SHOW_TIME | FORMAT_24HOUR; @@ -204,7 +205,7 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { int abbr12 = time12 | FORMAT_ABBREV_ALL; int abbr24 = time24 | FORMAT_ABBREV_ALL; - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); // Full length on-the-hour times. @@ -231,7 +232,7 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { // http://b/10560853 - when the time is not displayed, an end time 0 ms into the next day is // considered to belong to the previous day. public void test10560853_when_time_not_displayed() throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); long midnight = 0; @@ -255,7 +256,7 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { // http://b/10560853 - when the start and end times are otherwise on the same day, // an end time 0 ms into the next day is considered to belong to the previous day. public void test10560853_for_single_day_events() throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); int flags = FORMAT_SHOW_TIME | FORMAT_24HOUR | FORMAT_SHOW_DATE; @@ -267,7 +268,7 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { // The fix for http://b/10560853 didn't work except for the day around the epoch, which was // all the unit test checked! public void test_single_day_events_later_than_epoch() throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); int flags = FORMAT_SHOW_TIME | FORMAT_24HOUR | FORMAT_SHOW_DATE; @@ -285,7 +286,7 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { // The fix for http://b/10560853 didn't work except for UTC, which was // all the unit test checked! public void test_single_day_events_not_in_UTC() throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone pacific = TimeZone.getTimeZone("America/Los_Angeles"); int flags = FORMAT_SHOW_TIME | FORMAT_24HOUR | FORMAT_SHOW_DATE; @@ -306,7 +307,7 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { // http://b/10209343 - even if the caller didn't explicitly ask us to include the year, // we should do so for years other than the current year. public void test10209343_when_not_this_year() { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY | FORMAT_SHOW_TIME | FORMAT_24HOUR; @@ -329,7 +330,7 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { // http://b/10209343 - for the current year, we should honor the FORMAT_SHOW_YEAR flags. public void test10209343_when_this_year() { // Construct a date in the current year (whenever the test happens to be run). - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); Calendar c = Calendar.getInstance(utc, l); c.set(Calendar.MONTH, Calendar.FEBRUARY); @@ -364,7 +365,7 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { // http://b/8467515 - yet another y2k38 bug report. public void test8467515() throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY | FORMAT_SHOW_YEAR | FORMAT_ABBREV_MONTH | FORMAT_ABBREV_WEEKDAY; long t; @@ -384,7 +385,7 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { // http://b/12004664 public void test12004664() throws Exception { TimeZone utc = TimeZone.getTimeZone("UTC"); - Calendar c = Calendar.getInstance(utc, Locale.US); + Calendar c = Calendar.getInstance(utc, ULocale.US); c.clear(); c.set(Calendar.YEAR, 1980); c.set(Calendar.MONTH, Calendar.FEBRUARY); @@ -393,26 +394,26 @@ public class DateIntervalFormatTest extends junit.framework.TestCase { long thisYear = c.getTimeInMillis(); int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY | FORMAT_SHOW_YEAR; - assertEquals("Sunday, February 10, 1980", formatDateRange(new Locale("en", "US"), utc, thisYear, thisYear, flags)); + assertEquals("Sunday, February 10, 1980", formatDateRange(new ULocale("en", "US"), utc, thisYear, thisYear, flags)); - // If we supported non-Gregorian calendars, this is what that we'd expect for these locales. + // If we supported non-Gregorian calendars, this is what that we'd expect for these ULocales. // This is really the correct behavior, but since java.util.Calendar currently only supports // the Gregorian calendar, we want to deliberately force icu4c to agree, otherwise we'd have // a mix of calendars throughout an app's UI depending on whether Java or native code formatted // the date. - // assertEquals("یکشنبه ۲۱ بهمن ۱۳۵۸ ه.ش.", formatDateRange(new Locale("fa"), utc, thisYear, thisYear, flags)); - // assertEquals("AP ۱۳۵۸ سلواغه ۲۱, یکشنبه", formatDateRange(new Locale("ps"), utc, thisYear, thisYear, flags)); - // assertEquals("วันอาทิตย์ 10 กุมภาพันธ์ 2523", formatDateRange(new Locale("th"), utc, thisYear, thisYear, flags)); + // assertEquals("یکشنبه ۲۱ بهمن ۱۳۵۸ ه.ش.", formatDateRange(new ULocale("fa"), utc, thisYear, thisYear, flags)); + // assertEquals("AP ۱۳۵۸ سلواغه ۲۱, یکشنبه", formatDateRange(new ULocale("ps"), utc, thisYear, thisYear, flags)); + // assertEquals("วันอาทิตย์ 10 กุมภาพันธ์ 2523", formatDateRange(new ULocale("th"), utc, thisYear, thisYear, flags)); // For now, here are the localized Gregorian strings instead... - assertEquals("یکشنبه ۱۰ فوریهٔ ۱۹۸۰", formatDateRange(new Locale("fa"), utc, thisYear, thisYear, flags)); - assertEquals("یکشنبه د ۱۹۸۰ د فبروري ۱۰", formatDateRange(new Locale("ps"), utc, thisYear, thisYear, flags)); - assertEquals("วันอาทิตย์ที่ 10 กุมภาพันธ์ ค.ศ. 1980", formatDateRange(new Locale("th"), utc, thisYear, thisYear, flags)); + assertEquals("یکشنبه ۱۰ فوریهٔ ۱۹۸۰", formatDateRange(new ULocale("fa"), utc, thisYear, thisYear, flags)); + assertEquals("یکشنبه د ۱۹۸۰ د فبروري ۱۰", formatDateRange(new ULocale("ps"), utc, thisYear, thisYear, flags)); + assertEquals("วันอาทิตย์ที่ 10 กุมภาพันธ์ ค.ศ. 1980", formatDateRange(new ULocale("th"), utc, thisYear, thisYear, flags)); } // http://b/13234532 public void test13234532() throws Exception { - Locale l = Locale.US; + ULocale l = ULocale.US; TimeZone utc = TimeZone.getTimeZone("UTC"); int flags = FORMAT_SHOW_TIME | FORMAT_ABBREV_ALL | FORMAT_12HOUR; |