• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/i18n/time_formatting.h"
6 
7 #include <memory>
8 
9 #include "base/i18n/rtl.h"
10 #include "base/i18n/unicodestring.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/test/icu_test_util.h"
13 #include "base/time/time.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/icu/source/common/unicode/uversion.h"
16 #include "third_party/icu/source/i18n/unicode/calendar.h"
17 #include "third_party/icu/source/i18n/unicode/timezone.h"
18 #include "third_party/icu/source/i18n/unicode/tzfmt.h"
19 
20 namespace base {
21 namespace {
22 
23 const Time::Exploded kTestDateTimeExploded = {
24     2011, 4,  6, 30,  // Sat, Apr 30, 2011
25     22,   42, 7, 0    // 22:42:07.000 in UTC = 15:42:07 in US PDT.
26 };
27 
28 // Returns difference between the local time and GMT formatted as string.
29 // This function gets |time| because the difference depends on time,
30 // see https://en.wikipedia.org/wiki/Daylight_saving_time for details.
GetShortTimeZone(const Time & time)31 string16 GetShortTimeZone(const Time& time) {
32   UErrorCode status = U_ZERO_ERROR;
33   std::unique_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault());
34   std::unique_ptr<icu::TimeZoneFormat> zone_formatter(
35       icu::TimeZoneFormat::createInstance(icu::Locale::getDefault(), status));
36   EXPECT_TRUE(U_SUCCESS(status));
37   icu::UnicodeString name;
38   zone_formatter->format(UTZFMT_STYLE_SPECIFIC_SHORT, *zone,
39                          static_cast<UDate>(time.ToDoubleT() * 1000),
40                          name, nullptr);
41   return i18n::UnicodeStringToString16(name);
42 }
43 
44 // Calls TimeDurationFormat() with |delta| and |width| and returns the resulting
45 // string. On failure, adds a failed expectation and returns an empty string.
TimeDurationFormatString(const TimeDelta & delta,DurationFormatWidth width)46 string16 TimeDurationFormatString(const TimeDelta& delta,
47                                   DurationFormatWidth width) {
48   string16 str;
49   EXPECT_TRUE(TimeDurationFormat(delta, width, &str))
50       << "Failed to format " << delta.ToInternalValue() << " with width "
51       << width;
52   return str;
53 }
54 
55 // Calls TimeDurationFormatWithSeconds() with |delta| and |width| and returns
56 // the resulting string. On failure, adds a failed expectation and returns an
57 // empty string.
TimeDurationFormatWithSecondsString(const TimeDelta & delta,DurationFormatWidth width)58 string16 TimeDurationFormatWithSecondsString(const TimeDelta& delta,
59                                              DurationFormatWidth width) {
60   string16 str;
61   EXPECT_TRUE(TimeDurationFormatWithSeconds(delta, width, &str))
62       << "Failed to format " << delta.ToInternalValue() << " with width "
63       << width;
64   return str;
65 }
66 
67 class ScopedRestoreDefaultTimezone {
68  public:
ScopedRestoreDefaultTimezone(const char * zoneid)69   ScopedRestoreDefaultTimezone(const char* zoneid) {
70     original_zone_.reset(icu::TimeZone::createDefault());
71     icu::TimeZone::adoptDefault(icu::TimeZone::createTimeZone(zoneid));
72   }
~ScopedRestoreDefaultTimezone()73   ~ScopedRestoreDefaultTimezone() {
74     icu::TimeZone::adoptDefault(original_zone_.release());
75   }
76 
77   ScopedRestoreDefaultTimezone(const ScopedRestoreDefaultTimezone&) = delete;
78   ScopedRestoreDefaultTimezone& operator=(const ScopedRestoreDefaultTimezone&) =
79       delete;
80 
81  private:
82   std::unique_ptr<icu::TimeZone> original_zone_;
83 };
84 
TEST(TimeFormattingTest,TimeFormatTimeOfDayDefault12h)85 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) {
86   // Test for a locale defaulted to 12h clock.
87   // As an instance, we use third_party/icu/source/data/locales/en.txt.
88   test::ScopedRestoreICUDefaultLocale restore_locale;
89   i18n::SetICUDefaultLocale("en_US");
90   ScopedRestoreDefaultTimezone la_time("America/Los_Angeles");
91 
92   Time time;
93   EXPECT_TRUE(Time::FromUTCExploded(kTestDateTimeExploded, &time));
94   string16 clock24h(ASCIIToUTF16("15:42"));
95   string16 clock12h_pm(ASCIIToUTF16("3:42 PM"));
96   string16 clock12h(ASCIIToUTF16("3:42"));
97   string16 clock24h_millis(ASCIIToUTF16("15:42:07.000"));
98 
99   // The default is 12h clock.
100   EXPECT_EQ(clock12h_pm, TimeFormatTimeOfDay(time));
101   EXPECT_EQ(clock24h_millis, TimeFormatTimeOfDayWithMilliseconds(time));
102   EXPECT_EQ(k12HourClock, GetHourClockType());
103   // k{Keep,Drop}AmPm should not affect for 24h clock.
104   EXPECT_EQ(clock24h,
105             TimeFormatTimeOfDayWithHourClockType(time,
106                                                  k24HourClock,
107                                                  kKeepAmPm));
108   EXPECT_EQ(clock24h,
109             TimeFormatTimeOfDayWithHourClockType(time,
110                                                  k24HourClock,
111                                                  kDropAmPm));
112   // k{Keep,Drop}AmPm affects for 12h clock.
113   EXPECT_EQ(clock12h_pm,
114             TimeFormatTimeOfDayWithHourClockType(time,
115                                                  k12HourClock,
116                                                  kKeepAmPm));
117   EXPECT_EQ(clock12h,
118             TimeFormatTimeOfDayWithHourClockType(time,
119                                                  k12HourClock,
120                                                  kDropAmPm));
121 }
122 
TEST(TimeFormattingTest,TimeFormatTimeOfDayDefault24h)123 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault24h) {
124   // Test for a locale defaulted to 24h clock.
125   // As an instance, we use third_party/icu/source/data/locales/en_GB.txt.
126   test::ScopedRestoreICUDefaultLocale restore_locale;
127   i18n::SetICUDefaultLocale("en_GB");
128   ScopedRestoreDefaultTimezone la_time("America/Los_Angeles");
129 
130   Time time;
131   EXPECT_TRUE(Time::FromUTCExploded(kTestDateTimeExploded, &time));
132   string16 clock24h(ASCIIToUTF16("15:42"));
133   string16 clock12h_pm(ASCIIToUTF16("3:42 pm"));
134   string16 clock12h(ASCIIToUTF16("3:42"));
135   string16 clock24h_millis(ASCIIToUTF16("15:42:07.000"));
136 
137   // The default is 24h clock.
138   EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time));
139   EXPECT_EQ(clock24h_millis, TimeFormatTimeOfDayWithMilliseconds(time));
140   EXPECT_EQ(k24HourClock, GetHourClockType());
141   // k{Keep,Drop}AmPm should not affect for 24h clock.
142   EXPECT_EQ(clock24h,
143             TimeFormatTimeOfDayWithHourClockType(time,
144                                                  k24HourClock,
145                                                  kKeepAmPm));
146   EXPECT_EQ(clock24h,
147             TimeFormatTimeOfDayWithHourClockType(time,
148                                                  k24HourClock,
149                                                  kDropAmPm));
150   // k{Keep,Drop}AmPm affects for 12h clock.
151   EXPECT_EQ(clock12h_pm,
152             TimeFormatTimeOfDayWithHourClockType(time,
153                                                  k12HourClock,
154                                                  kKeepAmPm));
155   EXPECT_EQ(clock12h,
156             TimeFormatTimeOfDayWithHourClockType(time,
157                                                  k12HourClock,
158                                                  kDropAmPm));
159 }
160 
TEST(TimeFormattingTest,TimeFormatTimeOfDayJP)161 TEST(TimeFormattingTest, TimeFormatTimeOfDayJP) {
162   // Test for a locale that uses different mark than "AM" and "PM".
163   // As an instance, we use third_party/icu/source/data/locales/ja.txt.
164   test::ScopedRestoreICUDefaultLocale restore_locale;
165   i18n::SetICUDefaultLocale("ja_JP");
166   ScopedRestoreDefaultTimezone la_time("America/Los_Angeles");
167 
168   Time time;
169   EXPECT_TRUE(Time::FromUTCExploded(kTestDateTimeExploded, &time));
170   string16 clock24h(ASCIIToUTF16("15:42"));
171   string16 clock12h_pm(UTF8ToUTF16(u8"午後3:42"));
172   string16 clock12h(ASCIIToUTF16("3:42"));
173 
174   // The default is 24h clock.
175   EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time));
176   EXPECT_EQ(k24HourClock, GetHourClockType());
177   // k{Keep,Drop}AmPm should not affect for 24h clock.
178   EXPECT_EQ(clock24h, TimeFormatTimeOfDayWithHourClockType(time, k24HourClock,
179                                                            kKeepAmPm));
180   EXPECT_EQ(clock24h, TimeFormatTimeOfDayWithHourClockType(time, k24HourClock,
181                                                            kDropAmPm));
182   // k{Keep,Drop}AmPm affects for 12h clock.
183   EXPECT_EQ(clock12h_pm, TimeFormatTimeOfDayWithHourClockType(
184                              time, k12HourClock, kKeepAmPm));
185   EXPECT_EQ(clock12h, TimeFormatTimeOfDayWithHourClockType(time, k12HourClock,
186                                                            kDropAmPm));
187 }
188 
TEST(TimeFormattingTest,TimeFormatTimeOfDayDE)189 TEST(TimeFormattingTest, TimeFormatTimeOfDayDE) {
190   // German uses 24h by default, but uses 'AM', 'PM' for 12h format.
191   test::ScopedRestoreICUDefaultLocale restore_locale;
192   i18n::SetICUDefaultLocale("de");
193   ScopedRestoreDefaultTimezone la_time("America/Los_Angeles");
194 
195   Time time;
196   EXPECT_TRUE(Time::FromUTCExploded(kTestDateTimeExploded, &time));
197   string16 clock24h(ASCIIToUTF16("15:42"));
198   string16 clock12h_pm(UTF8ToUTF16("3:42 PM"));
199   string16 clock12h(ASCIIToUTF16("3:42"));
200 
201   // The default is 24h clock.
202   EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time));
203   EXPECT_EQ(k24HourClock, GetHourClockType());
204   // k{Keep,Drop}AmPm should not affect for 24h clock.
205   EXPECT_EQ(clock24h,
206             TimeFormatTimeOfDayWithHourClockType(time,
207                                                  k24HourClock,
208                                                  kKeepAmPm));
209   EXPECT_EQ(clock24h,
210             TimeFormatTimeOfDayWithHourClockType(time,
211                                                  k24HourClock,
212                                                  kDropAmPm));
213   // k{Keep,Drop}AmPm affects for 12h clock.
214   EXPECT_EQ(clock12h_pm,
215             TimeFormatTimeOfDayWithHourClockType(time,
216                                                  k12HourClock,
217                                                  kKeepAmPm));
218   EXPECT_EQ(clock12h,
219             TimeFormatTimeOfDayWithHourClockType(time,
220                                                  k12HourClock,
221                                                  kDropAmPm));
222 }
223 
TEST(TimeFormattingTest,TimeFormatDateUS)224 TEST(TimeFormattingTest, TimeFormatDateUS) {
225   // See third_party/icu/source/data/locales/en.txt.
226   // The date patterns are "EEEE, MMMM d, y", "MMM d, y", and "M/d/yy".
227   test::ScopedRestoreICUDefaultLocale restore_locale;
228   i18n::SetICUDefaultLocale("en_US");
229   ScopedRestoreDefaultTimezone la_time("America/Los_Angeles");
230 
231   Time time;
232   EXPECT_TRUE(Time::FromUTCExploded(kTestDateTimeExploded, &time));
233 
234   EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time));
235   EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time));
236 
237   EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"),
238             TimeFormatShortDateAndTime(time));
239   EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM ") + GetShortTimeZone(time),
240             TimeFormatShortDateAndTimeWithTimeZone(time));
241 
242   EXPECT_EQ(ASCIIToUTF16("April 2011"), TimeFormatMonthAndYear(time));
243 
244   EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"),
245             TimeFormatFriendlyDateAndTime(time));
246 
247   EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"),
248             TimeFormatFriendlyDate(time));
249 }
250 
TEST(TimeFormattingTest,TimeFormatDateGB)251 TEST(TimeFormattingTest, TimeFormatDateGB) {
252   // See third_party/icu/source/data/locales/en_GB.txt.
253   // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy".
254   test::ScopedRestoreICUDefaultLocale restore_locale;
255   i18n::SetICUDefaultLocale("en_GB");
256   ScopedRestoreDefaultTimezone la_time("America/Los_Angeles");
257 
258   Time time;
259   EXPECT_TRUE(Time::FromUTCExploded(kTestDateTimeExploded, &time));
260 
261   EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time));
262   EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time));
263   EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07"),
264             TimeFormatShortDateAndTime(time));
265   EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(time),
266             TimeFormatShortDateAndTimeWithTimeZone(time));
267   EXPECT_EQ(ASCIIToUTF16("April 2011"), TimeFormatMonthAndYear(time));
268   EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 at 15:42:07"),
269             TimeFormatFriendlyDateAndTime(time));
270   EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"),
271             TimeFormatFriendlyDate(time));
272 }
273 
TEST(TimeFormattingTest,TimeFormatWithPattern)274 TEST(TimeFormattingTest, TimeFormatWithPattern) {
275   test::ScopedRestoreICUDefaultLocale restore_locale;
276   ScopedRestoreDefaultTimezone la_time("America/Los_Angeles");
277 
278   Time time;
279   EXPECT_TRUE(Time::FromUTCExploded(kTestDateTimeExploded, &time));
280 
281   i18n::SetICUDefaultLocale("en_US");
282   EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatWithPattern(time, "yMMMd"));
283   EXPECT_EQ(ASCIIToUTF16("April 30, 3:42:07 PM"),
284             TimeFormatWithPattern(time, "MMMMdjmmss"));
285 
286   i18n::SetICUDefaultLocale("en_GB");
287   EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatWithPattern(time, "yMMMd"));
288   EXPECT_EQ(ASCIIToUTF16("30 April, 15:42:07"),
289             TimeFormatWithPattern(time, "MMMMdjmmss"));
290 
291   i18n::SetICUDefaultLocale("ja_JP");
292   EXPECT_EQ(UTF8ToUTF16(u8"2011年4月30日"),
293             TimeFormatWithPattern(time, "yMMMd"));
294   EXPECT_EQ(UTF8ToUTF16(u8"4月30日 15:42:07"),
295             TimeFormatWithPattern(time, "MMMMdjmmss"));
296 }
297 
TEST(TimeFormattingTest,TimeDurationFormat)298 TEST(TimeFormattingTest, TimeDurationFormat) {
299   test::ScopedRestoreICUDefaultLocale restore_locale;
300   TimeDelta delta = TimeDelta::FromMinutes(15 * 60 + 42);
301 
302   // US English.
303   i18n::SetICUDefaultLocale("en_US");
304   EXPECT_EQ(ASCIIToUTF16("15 hours, 42 minutes"),
305             TimeDurationFormatString(delta, DURATION_WIDTH_WIDE));
306   EXPECT_EQ(ASCIIToUTF16("15 hr, 42 min"),
307             TimeDurationFormatString(delta, DURATION_WIDTH_SHORT));
308   EXPECT_EQ(ASCIIToUTF16("15h 42m"),
309             TimeDurationFormatString(delta, DURATION_WIDTH_NARROW));
310   EXPECT_EQ(ASCIIToUTF16("15:42"),
311             TimeDurationFormatString(delta, DURATION_WIDTH_NUMERIC));
312 
313   // Danish, with Latin alphabet but different abbreviations and punctuation.
314   i18n::SetICUDefaultLocale("da");
315   EXPECT_EQ(ASCIIToUTF16("15 timer og 42 minutter"),
316             TimeDurationFormatString(delta, DURATION_WIDTH_WIDE));
317   EXPECT_EQ(ASCIIToUTF16("15 t og 42 min."),
318             TimeDurationFormatString(delta, DURATION_WIDTH_SHORT));
319   EXPECT_EQ(ASCIIToUTF16("15 t og 42 min"),
320             TimeDurationFormatString(delta, DURATION_WIDTH_NARROW));
321   EXPECT_EQ(ASCIIToUTF16("15.42"),
322             TimeDurationFormatString(delta, DURATION_WIDTH_NUMERIC));
323 
324   // Persian, with non-Arabic numbers.
325   i18n::SetICUDefaultLocale("fa");
326   string16 fa_wide = UTF8ToUTF16(
327       u8"\u06f1\u06f5 \u0633\u0627\u0639\u062a \u0648 \u06f4\u06f2 \u062f\u0642"
328       u8"\u06cc\u0642\u0647");
329   string16 fa_short = UTF8ToUTF16(
330       u8"\u06f1\u06f5 \u0633\u0627\u0639\u062a\u060c\u200f \u06f4\u06f2 \u062f"
331       u8"\u0642\u06cc\u0642\u0647");
332   string16 fa_narrow = UTF8ToUTF16(
333       u8"\u06f1\u06f5 \u0633\u0627\u0639\u062a \u06f4\u06f2 \u062f\u0642\u06cc"
334       u8"\u0642\u0647");
335   string16 fa_numeric = UTF8ToUTF16(u8"\u06f1\u06f5:\u06f4\u06f2");
336   EXPECT_EQ(fa_wide, TimeDurationFormatString(delta, DURATION_WIDTH_WIDE));
337   EXPECT_EQ(fa_short, TimeDurationFormatString(delta, DURATION_WIDTH_SHORT));
338   EXPECT_EQ(fa_narrow, TimeDurationFormatString(delta, DURATION_WIDTH_NARROW));
339   EXPECT_EQ(fa_numeric,
340             TimeDurationFormatString(delta, DURATION_WIDTH_NUMERIC));
341 }
342 
TEST(TimeFormattingTest,TimeDurationFormatWithSeconds)343 TEST(TimeFormattingTest, TimeDurationFormatWithSeconds) {
344   test::ScopedRestoreICUDefaultLocale restore_locale;
345 
346   // US English.
347   i18n::SetICUDefaultLocale("en_US");
348 
349   // Test different formats.
350   TimeDelta delta = TimeDelta::FromSeconds(15 * 3600 + 42 * 60 + 30);
351   EXPECT_EQ(ASCIIToUTF16("15 hours, 42 minutes, 30 seconds"),
352             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_WIDE));
353   EXPECT_EQ(ASCIIToUTF16("15 hr, 42 min, 30 sec"),
354             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_SHORT));
355   EXPECT_EQ(ASCIIToUTF16("15h 42m 30s"),
356             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_NARROW));
357   EXPECT_EQ(ASCIIToUTF16("15:42:30"),
358             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_NUMERIC));
359 
360   // Test edge case when hour >= 100.
361   delta = TimeDelta::FromSeconds(125 * 3600 + 42 * 60 + 30);
362   EXPECT_EQ(ASCIIToUTF16("125 hours, 42 minutes, 30 seconds"),
363             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_WIDE));
364   EXPECT_EQ(ASCIIToUTF16("125 hr, 42 min, 30 sec"),
365             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_SHORT));
366   EXPECT_EQ(ASCIIToUTF16("125h 42m 30s"),
367             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_NARROW));
368 
369   // Test edge case when minute = 0.
370   delta = TimeDelta::FromSeconds(15 * 3600 + 0 * 60 + 30);
371   EXPECT_EQ(ASCIIToUTF16("15 hours, 0 minutes, 30 seconds"),
372             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_WIDE));
373   EXPECT_EQ(ASCIIToUTF16("15 hr, 0 min, 30 sec"),
374             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_SHORT));
375   EXPECT_EQ(ASCIIToUTF16("15h 0m 30s"),
376             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_NARROW));
377   EXPECT_EQ(ASCIIToUTF16("15:00:30"),
378             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_NUMERIC));
379 
380   // Test edge case when second = 0.
381   delta = TimeDelta::FromSeconds(15 * 3600 + 42 * 60 + 0);
382   EXPECT_EQ(ASCIIToUTF16("15 hours, 42 minutes, 0 seconds"),
383             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_WIDE));
384   EXPECT_EQ(ASCIIToUTF16("15 hr, 42 min, 0 sec"),
385             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_SHORT));
386   EXPECT_EQ(ASCIIToUTF16("15h 42m 0s"),
387             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_NARROW));
388   EXPECT_EQ(ASCIIToUTF16("15:42:00"),
389             TimeDurationFormatWithSecondsString(delta, DURATION_WIDTH_NUMERIC));
390 }
391 
TEST(TimeFormattingTest,TimeIntervalFormat)392 TEST(TimeFormattingTest, TimeIntervalFormat) {
393   test::ScopedRestoreICUDefaultLocale restore_locale;
394   i18n::SetICUDefaultLocale("en_US");
395   ScopedRestoreDefaultTimezone la_time("America/Los_Angeles");
396 
397   const Time::Exploded kTestIntervalEndTimeExploded = {
398       2011, 5,  6, 28,  // Sat, May 28, 2012
399       22,   42, 7, 0    // 22:42:07.000
400   };
401 
402   Time begin_time;
403   EXPECT_TRUE(Time::FromUTCExploded(kTestDateTimeExploded, &begin_time));
404   Time end_time;
405   EXPECT_TRUE(Time::FromUTCExploded(kTestIntervalEndTimeExploded, &end_time));
406 
407   EXPECT_EQ(
408       UTF8ToUTF16(u8"Saturday, April 30 – Saturday, May 28"),
409       DateIntervalFormat(begin_time, end_time, DATE_FORMAT_MONTH_WEEKDAY_DAY));
410 
411   const Time::Exploded kTestIntervalBeginTimeExploded = {
412       2011, 5,  1, 16,  // Mon, May 16, 2012
413       22,   42, 7, 0    // 22:42:07.000
414   };
415   EXPECT_TRUE(
416       Time::FromUTCExploded(kTestIntervalBeginTimeExploded, &begin_time));
417   EXPECT_EQ(
418       UTF8ToUTF16(u8"Monday, May 16 – Saturday, May 28"),
419       DateIntervalFormat(begin_time, end_time, DATE_FORMAT_MONTH_WEEKDAY_DAY));
420 
421   i18n::SetICUDefaultLocale("en_GB");
422   EXPECT_EQ(
423       UTF8ToUTF16(u8"Monday 16 – Saturday 28 May"),
424       DateIntervalFormat(begin_time, end_time, DATE_FORMAT_MONTH_WEEKDAY_DAY));
425 
426   i18n::SetICUDefaultLocale("ja");
427   EXPECT_EQ(
428       UTF8ToUTF16(u8"5月16日(月曜日)~28日(土曜日)"),
429       DateIntervalFormat(begin_time, end_time, DATE_FORMAT_MONTH_WEEKDAY_DAY));
430 }
431 
432 }  // namespace
433 }  // namespace base
434