OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/i18n/time_formatting.h" | 5 #include "base/i18n/time_formatting.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "unicode/uversion.h" |
11 | 12 |
12 namespace base { | 13 namespace base { |
13 namespace { | 14 namespace { |
14 | 15 |
15 const Time::Exploded kTestDateTimeExploded = { | 16 const Time::Exploded kTestDateTimeExploded = { |
16 2011, 4, 6, 30, // Sat, Apr 30, 2011 | 17 2011, 4, 6, 30, // Sat, Apr 30, 2011 |
17 15, 42, 7, 0 // 15:42:07.000 | 18 15, 42, 7, 0 // 15:42:07.000 |
18 }; | 19 }; |
19 | 20 |
20 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) { | 21 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) { |
(...skipping 29 matching lines...) Expand all Loading... |
50 kDropAmPm)); | 51 kDropAmPm)); |
51 } | 52 } |
52 | 53 |
53 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault24h) { | 54 TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault24h) { |
54 // Test for a locale defaulted to 24h clock. | 55 // Test for a locale defaulted to 24h clock. |
55 // As an instance, we use third_party/icu/source/data/locales/en_GB.txt. | 56 // As an instance, we use third_party/icu/source/data/locales/en_GB.txt. |
56 i18n::SetICUDefaultLocale("en_GB"); | 57 i18n::SetICUDefaultLocale("en_GB"); |
57 | 58 |
58 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); | 59 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); |
59 string16 clock24h(ASCIIToUTF16("15:42")); | 60 string16 clock24h(ASCIIToUTF16("15:42")); |
| 61 #if U_ICU_VERSION_MAJOR_NUM >= 50 |
| 62 string16 clock12h_pm(ASCIIToUTF16("3:42 pm")); |
| 63 #else |
| 64 // TODO(phajdan.jr): Clean up after bundled ICU gets updated to 50. |
60 string16 clock12h_pm(ASCIIToUTF16("3:42 PM")); | 65 string16 clock12h_pm(ASCIIToUTF16("3:42 PM")); |
| 66 #endif |
61 string16 clock12h(ASCIIToUTF16("3:42")); | 67 string16 clock12h(ASCIIToUTF16("3:42")); |
62 | 68 |
63 // The default is 24h clock. | 69 // The default is 24h clock. |
64 EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time)); | 70 EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time)); |
65 EXPECT_EQ(k24HourClock, GetHourClockType()); | 71 EXPECT_EQ(k24HourClock, GetHourClockType()); |
66 // k{Keep,Drop}AmPm should not affect for 24h clock. | 72 // k{Keep,Drop}AmPm should not affect for 24h clock. |
67 EXPECT_EQ(clock24h, | 73 EXPECT_EQ(clock24h, |
68 TimeFormatTimeOfDayWithHourClockType(time, | 74 TimeFormatTimeOfDayWithHourClockType(time, |
69 k24HourClock, | 75 k24HourClock, |
70 kKeepAmPm)); | 76 kKeepAmPm)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 124 |
119 TEST(TimeFormattingTest, TimeFormatDateUS) { | 125 TEST(TimeFormattingTest, TimeFormatDateUS) { |
120 // See third_party/icu/source/data/locales/en.txt. | 126 // See third_party/icu/source/data/locales/en.txt. |
121 // The date patterns are "EEEE, MMMM d, y", "MMM d, y", and "M/d/yy". | 127 // The date patterns are "EEEE, MMMM d, y", "MMM d, y", and "M/d/yy". |
122 i18n::SetICUDefaultLocale("en_US"); | 128 i18n::SetICUDefaultLocale("en_US"); |
123 | 129 |
124 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); | 130 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); |
125 | 131 |
126 EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time)); | 132 EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time)); |
127 EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time)); | 133 EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time)); |
| 134 |
| 135 #if U_ICU_VERSION_MAJOR_NUM >= 50 |
| 136 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"), |
| 137 TimeFormatShortDateAndTime(time)); |
| 138 #else |
| 139 // TODO(phajdan.jr): Clean up after bundled ICU gets updated to 50. |
128 EXPECT_EQ(ASCIIToUTF16("4/30/11 3:42:07 PM"), | 140 EXPECT_EQ(ASCIIToUTF16("4/30/11 3:42:07 PM"), |
129 TimeFormatShortDateAndTime(time)); | 141 TimeFormatShortDateAndTime(time)); |
| 142 #endif |
| 143 |
| 144 #if U_ICU_VERSION_MAJOR_NUM >= 50 |
| 145 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"), |
| 146 TimeFormatFriendlyDateAndTime(time)); |
| 147 #else |
| 148 // TODO(phajdan.jr): Clean up after bundled ICU gets updated to 50. |
130 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 3:42:07 PM"), | 149 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 3:42:07 PM"), |
131 TimeFormatFriendlyDateAndTime(time)); | 150 TimeFormatFriendlyDateAndTime(time)); |
| 151 #endif |
| 152 |
132 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"), | 153 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"), |
133 TimeFormatFriendlyDate(time)); | 154 TimeFormatFriendlyDate(time)); |
134 } | 155 } |
135 | 156 |
136 TEST(TimeFormattingTest, TimeFormatDateGB) { | 157 TEST(TimeFormattingTest, TimeFormatDateGB) { |
137 // See third_party/icu/source/data/locales/en_GB.txt. | 158 // See third_party/icu/source/data/locales/en_GB.txt. |
138 // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy". | 159 // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy". |
139 i18n::SetICUDefaultLocale("en_GB"); | 160 i18n::SetICUDefaultLocale("en_GB"); |
140 | 161 |
141 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); | 162 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); |
142 | 163 |
143 EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time)); | 164 EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time)); |
144 EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time)); | 165 EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time)); |
145 EXPECT_EQ(ASCIIToUTF16("30/04/2011 15:42:07"), | 166 EXPECT_EQ(ASCIIToUTF16("30/04/2011 15:42:07"), |
146 TimeFormatShortDateAndTime(time)); | 167 TimeFormatShortDateAndTime(time)); |
147 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 15:42:07"), | 168 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 15:42:07"), |
148 TimeFormatFriendlyDateAndTime(time)); | 169 TimeFormatFriendlyDateAndTime(time)); |
149 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"), | 170 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"), |
150 TimeFormatFriendlyDate(time)); | 171 TimeFormatFriendlyDate(time)); |
151 } | 172 } |
152 | 173 |
153 } // namespace | 174 } // namespace |
154 } // namespace base | 175 } // namespace base |
OLD | NEW |