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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 DISABLED_TimeFormatTimeOfDayDefault12h | 45 DISABLED_TimeFormatTimeOfDayDefault12h |
46 #else | 46 #else |
47 #define MAYBE_TimeFormatTimeOfDayDefault12h TimeFormatTimeOfDayDefault12h | 47 #define MAYBE_TimeFormatTimeOfDayDefault12h TimeFormatTimeOfDayDefault12h |
48 #endif | 48 #endif |
49 TEST(TimeFormattingTest, MAYBE_TimeFormatTimeOfDayDefault12h) { | 49 TEST(TimeFormattingTest, MAYBE_TimeFormatTimeOfDayDefault12h) { |
50 // Test for a locale defaulted to 12h clock. | 50 // Test for a locale defaulted to 12h clock. |
51 // As an instance, we use third_party/icu/source/data/locales/en.txt. | 51 // As an instance, we use third_party/icu/source/data/locales/en.txt. |
52 test::ScopedRestoreICUDefaultLocale restore_locale; | 52 test::ScopedRestoreICUDefaultLocale restore_locale; |
53 i18n::SetICUDefaultLocale("en_US"); | 53 i18n::SetICUDefaultLocale("en_US"); |
54 | 54 |
55 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); | 55 Time time; |
| 56 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &time)); |
56 string16 clock24h(ASCIIToUTF16("15:42")); | 57 string16 clock24h(ASCIIToUTF16("15:42")); |
57 string16 clock12h_pm(ASCIIToUTF16("3:42 PM")); | 58 string16 clock12h_pm(ASCIIToUTF16("3:42 PM")); |
58 string16 clock12h(ASCIIToUTF16("3:42")); | 59 string16 clock12h(ASCIIToUTF16("3:42")); |
59 string16 clock24h_millis(ASCIIToUTF16("15:42:07.000")); | 60 string16 clock24h_millis(ASCIIToUTF16("15:42:07.000")); |
60 | 61 |
61 // The default is 12h clock. | 62 // The default is 12h clock. |
62 EXPECT_EQ(clock12h_pm, TimeFormatTimeOfDay(time)); | 63 EXPECT_EQ(clock12h_pm, TimeFormatTimeOfDay(time)); |
63 EXPECT_EQ(clock24h_millis, TimeFormatTimeOfDayWithMilliseconds(time)); | 64 EXPECT_EQ(clock24h_millis, TimeFormatTimeOfDayWithMilliseconds(time)); |
64 EXPECT_EQ(k12HourClock, GetHourClockType()); | 65 EXPECT_EQ(k12HourClock, GetHourClockType()); |
65 // k{Keep,Drop}AmPm should not affect for 24h clock. | 66 // k{Keep,Drop}AmPm should not affect for 24h clock. |
(...skipping 21 matching lines...) Expand all Loading... |
87 DISABLED_TimeFormatTimeOfDayDefault24h | 88 DISABLED_TimeFormatTimeOfDayDefault24h |
88 #else | 89 #else |
89 #define MAYBE_TimeFormatTimeOfDayDefault24h TimeFormatTimeOfDayDefault24h | 90 #define MAYBE_TimeFormatTimeOfDayDefault24h TimeFormatTimeOfDayDefault24h |
90 #endif | 91 #endif |
91 TEST(TimeFormattingTest, MAYBE_TimeFormatTimeOfDayDefault24h) { | 92 TEST(TimeFormattingTest, MAYBE_TimeFormatTimeOfDayDefault24h) { |
92 // Test for a locale defaulted to 24h clock. | 93 // Test for a locale defaulted to 24h clock. |
93 // As an instance, we use third_party/icu/source/data/locales/en_GB.txt. | 94 // As an instance, we use third_party/icu/source/data/locales/en_GB.txt. |
94 test::ScopedRestoreICUDefaultLocale restore_locale; | 95 test::ScopedRestoreICUDefaultLocale restore_locale; |
95 i18n::SetICUDefaultLocale("en_GB"); | 96 i18n::SetICUDefaultLocale("en_GB"); |
96 | 97 |
97 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); | 98 Time time; |
| 99 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &time)); |
98 string16 clock24h(ASCIIToUTF16("15:42")); | 100 string16 clock24h(ASCIIToUTF16("15:42")); |
99 string16 clock12h_pm(ASCIIToUTF16("3:42 pm")); | 101 string16 clock12h_pm(ASCIIToUTF16("3:42 pm")); |
100 string16 clock12h(ASCIIToUTF16("3:42")); | 102 string16 clock12h(ASCIIToUTF16("3:42")); |
101 string16 clock24h_millis(ASCIIToUTF16("15:42:07.000")); | 103 string16 clock24h_millis(ASCIIToUTF16("15:42:07.000")); |
102 | 104 |
103 // The default is 24h clock. | 105 // The default is 24h clock. |
104 EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time)); | 106 EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time)); |
105 EXPECT_EQ(clock24h_millis, TimeFormatTimeOfDayWithMilliseconds(time)); | 107 EXPECT_EQ(clock24h_millis, TimeFormatTimeOfDayWithMilliseconds(time)); |
106 EXPECT_EQ(k24HourClock, GetHourClockType()); | 108 EXPECT_EQ(k24HourClock, GetHourClockType()); |
107 // k{Keep,Drop}AmPm should not affect for 24h clock. | 109 // k{Keep,Drop}AmPm should not affect for 24h clock. |
(...skipping 20 matching lines...) Expand all Loading... |
128 #define MAYBE_TimeFormatTimeOfDayJP DISABLED_TimeFormatTimeOfDayJP | 130 #define MAYBE_TimeFormatTimeOfDayJP DISABLED_TimeFormatTimeOfDayJP |
129 #else | 131 #else |
130 #define MAYBE_TimeFormatTimeOfDayJP TimeFormatTimeOfDayJP | 132 #define MAYBE_TimeFormatTimeOfDayJP TimeFormatTimeOfDayJP |
131 #endif | 133 #endif |
132 TEST(TimeFormattingTest, MAYBE_TimeFormatTimeOfDayJP) { | 134 TEST(TimeFormattingTest, MAYBE_TimeFormatTimeOfDayJP) { |
133 // Test for a locale that uses different mark than "AM" and "PM". | 135 // Test for a locale that uses different mark than "AM" and "PM". |
134 // As an instance, we use third_party/icu/source/data/locales/ja.txt. | 136 // As an instance, we use third_party/icu/source/data/locales/ja.txt. |
135 test::ScopedRestoreICUDefaultLocale restore_locale; | 137 test::ScopedRestoreICUDefaultLocale restore_locale; |
136 i18n::SetICUDefaultLocale("ja_JP"); | 138 i18n::SetICUDefaultLocale("ja_JP"); |
137 | 139 |
138 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); | 140 Time time; |
| 141 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &time)); |
139 string16 clock24h(ASCIIToUTF16("15:42")); | 142 string16 clock24h(ASCIIToUTF16("15:42")); |
140 string16 clock12h_pm(WideToUTF16(L"\x5348\x5f8c" L"3:42")); | 143 string16 clock12h_pm(WideToUTF16(L"\x5348\x5f8c" L"3:42")); |
141 string16 clock12h(ASCIIToUTF16("3:42")); | 144 string16 clock12h(ASCIIToUTF16("3:42")); |
142 | 145 |
143 // The default is 24h clock. | 146 // The default is 24h clock. |
144 EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time)); | 147 EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time)); |
145 EXPECT_EQ(k24HourClock, GetHourClockType()); | 148 EXPECT_EQ(k24HourClock, GetHourClockType()); |
146 // k{Keep,Drop}AmPm should not affect for 24h clock. | 149 // k{Keep,Drop}AmPm should not affect for 24h clock. |
147 EXPECT_EQ(clock24h, | 150 EXPECT_EQ(clock24h, |
148 TimeFormatTimeOfDayWithHourClockType(time, | 151 TimeFormatTimeOfDayWithHourClockType(time, |
(...skipping 18 matching lines...) Expand all Loading... |
167 #define MAYBE_TimeFormatDateUS DISABLED_TimeFormatDateUS | 170 #define MAYBE_TimeFormatDateUS DISABLED_TimeFormatDateUS |
168 #else | 171 #else |
169 #define MAYBE_TimeFormatDateUS TimeFormatDateUS | 172 #define MAYBE_TimeFormatDateUS TimeFormatDateUS |
170 #endif | 173 #endif |
171 TEST(TimeFormattingTest, MAYBE_TimeFormatDateUS) { | 174 TEST(TimeFormattingTest, MAYBE_TimeFormatDateUS) { |
172 // See third_party/icu/source/data/locales/en.txt. | 175 // See third_party/icu/source/data/locales/en.txt. |
173 // The date patterns are "EEEE, MMMM d, y", "MMM d, y", and "M/d/yy". | 176 // The date patterns are "EEEE, MMMM d, y", "MMM d, y", and "M/d/yy". |
174 test::ScopedRestoreICUDefaultLocale restore_locale; | 177 test::ScopedRestoreICUDefaultLocale restore_locale; |
175 i18n::SetICUDefaultLocale("en_US"); | 178 i18n::SetICUDefaultLocale("en_US"); |
176 | 179 |
177 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); | 180 Time time; |
| 181 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &time)); |
178 | 182 |
179 EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time)); | 183 EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time)); |
180 EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time)); | 184 EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time)); |
181 | 185 |
182 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"), | 186 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"), |
183 TimeFormatShortDateAndTime(time)); | 187 TimeFormatShortDateAndTime(time)); |
184 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM ") + GetShortTimeZone(time), | 188 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM ") + GetShortTimeZone(time), |
185 TimeFormatShortDateAndTimeWithTimeZone(time)); | 189 TimeFormatShortDateAndTimeWithTimeZone(time)); |
186 | 190 |
187 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"), | 191 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"), |
188 TimeFormatFriendlyDateAndTime(time)); | 192 TimeFormatFriendlyDateAndTime(time)); |
189 | 193 |
190 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"), | 194 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"), |
191 TimeFormatFriendlyDate(time)); | 195 TimeFormatFriendlyDate(time)); |
192 } | 196 } |
193 | 197 |
194 #if defined(OS_ANDROID) | 198 #if defined(OS_ANDROID) |
195 #define MAYBE_TimeFormatDateGB DISABLED_TimeFormatDateGB | 199 #define MAYBE_TimeFormatDateGB DISABLED_TimeFormatDateGB |
196 #else | 200 #else |
197 #define MAYBE_TimeFormatDateGB TimeFormatDateGB | 201 #define MAYBE_TimeFormatDateGB TimeFormatDateGB |
198 #endif | 202 #endif |
199 TEST(TimeFormattingTest, MAYBE_TimeFormatDateGB) { | 203 TEST(TimeFormattingTest, MAYBE_TimeFormatDateGB) { |
200 // See third_party/icu/source/data/locales/en_GB.txt. | 204 // See third_party/icu/source/data/locales/en_GB.txt. |
201 // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy". | 205 // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy". |
202 test::ScopedRestoreICUDefaultLocale restore_locale; | 206 test::ScopedRestoreICUDefaultLocale restore_locale; |
203 i18n::SetICUDefaultLocale("en_GB"); | 207 i18n::SetICUDefaultLocale("en_GB"); |
204 | 208 |
205 Time time(Time::FromLocalExploded(kTestDateTimeExploded)); | 209 Time time; |
| 210 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &time)); |
206 | 211 |
207 EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time)); | 212 EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time)); |
208 EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time)); | 213 EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time)); |
209 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07"), | 214 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07"), |
210 TimeFormatShortDateAndTime(time)); | 215 TimeFormatShortDateAndTime(time)); |
211 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(time), | 216 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(time), |
212 TimeFormatShortDateAndTimeWithTimeZone(time)); | 217 TimeFormatShortDateAndTimeWithTimeZone(time)); |
213 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 at 15:42:07"), | 218 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 at 15:42:07"), |
214 TimeFormatFriendlyDateAndTime(time)); | 219 TimeFormatFriendlyDateAndTime(time)); |
215 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"), | 220 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 L"\x642\x647"); | 260 L"\x642\x647"); |
256 string16 fa_numeric = WideToUTF16(L"\x6f1\x6f5\x3a\x6f4\x6f2"); | 261 string16 fa_numeric = WideToUTF16(L"\x6f1\x6f5\x3a\x6f4\x6f2"); |
257 EXPECT_EQ(fa_wide, TimeDurationFormat(delta, DURATION_WIDTH_WIDE)); | 262 EXPECT_EQ(fa_wide, TimeDurationFormat(delta, DURATION_WIDTH_WIDE)); |
258 EXPECT_EQ(fa_short, TimeDurationFormat(delta, DURATION_WIDTH_SHORT)); | 263 EXPECT_EQ(fa_short, TimeDurationFormat(delta, DURATION_WIDTH_SHORT)); |
259 EXPECT_EQ(fa_narrow, TimeDurationFormat(delta, DURATION_WIDTH_NARROW)); | 264 EXPECT_EQ(fa_narrow, TimeDurationFormat(delta, DURATION_WIDTH_NARROW)); |
260 EXPECT_EQ(fa_numeric, TimeDurationFormat(delta, DURATION_WIDTH_NUMERIC)); | 265 EXPECT_EQ(fa_numeric, TimeDurationFormat(delta, DURATION_WIDTH_NUMERIC)); |
261 } | 266 } |
262 | 267 |
263 } // namespace | 268 } // namespace |
264 } // namespace base | 269 } // namespace base |
OLD | NEW |