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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &time)); | 181 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &time)); |
182 | 182 |
183 EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time)); | 183 EXPECT_EQ(ASCIIToUTF16("Apr 30, 2011"), TimeFormatShortDate(time)); |
184 EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time)); | 184 EXPECT_EQ(ASCIIToUTF16("4/30/11"), TimeFormatShortDateNumeric(time)); |
185 | 185 |
186 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"), | 186 EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"), |
187 TimeFormatShortDateAndTime(time)); | 187 TimeFormatShortDateAndTime(time)); |
188 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), |
189 TimeFormatShortDateAndTimeWithTimeZone(time)); | 189 TimeFormatShortDateAndTimeWithTimeZone(time)); |
190 | 190 |
| 191 EXPECT_EQ(ASCIIToUTF16("April 2011"), TimeFormatMonthAndYear(time)); |
| 192 |
191 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"), | 193 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"), |
192 TimeFormatFriendlyDateAndTime(time)); | 194 TimeFormatFriendlyDateAndTime(time)); |
193 | 195 |
194 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"), | 196 EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011"), |
195 TimeFormatFriendlyDate(time)); | 197 TimeFormatFriendlyDate(time)); |
196 } | 198 } |
197 | 199 |
198 #if defined(OS_ANDROID) | 200 #if defined(OS_ANDROID) |
199 #define MAYBE_TimeFormatDateGB DISABLED_TimeFormatDateGB | 201 #define MAYBE_TimeFormatDateGB DISABLED_TimeFormatDateGB |
200 #else | 202 #else |
201 #define MAYBE_TimeFormatDateGB TimeFormatDateGB | 203 #define MAYBE_TimeFormatDateGB TimeFormatDateGB |
202 #endif | 204 #endif |
203 TEST(TimeFormattingTest, MAYBE_TimeFormatDateGB) { | 205 TEST(TimeFormattingTest, MAYBE_TimeFormatDateGB) { |
204 // See third_party/icu/source/data/locales/en_GB.txt. | 206 // See third_party/icu/source/data/locales/en_GB.txt. |
205 // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy". | 207 // The date patterns are "EEEE, d MMMM y", "d MMM y", and "dd/MM/yyyy". |
206 test::ScopedRestoreICUDefaultLocale restore_locale; | 208 test::ScopedRestoreICUDefaultLocale restore_locale; |
207 i18n::SetICUDefaultLocale("en_GB"); | 209 i18n::SetICUDefaultLocale("en_GB"); |
208 | 210 |
209 Time time; | 211 Time time; |
210 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &time)); | 212 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &time)); |
211 | 213 |
212 EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time)); | 214 EXPECT_EQ(ASCIIToUTF16("30 Apr 2011"), TimeFormatShortDate(time)); |
213 EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time)); | 215 EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time)); |
214 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07"), | 216 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07"), |
215 TimeFormatShortDateAndTime(time)); | 217 TimeFormatShortDateAndTime(time)); |
216 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(time), | 218 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(time), |
217 TimeFormatShortDateAndTimeWithTimeZone(time)); | 219 TimeFormatShortDateAndTimeWithTimeZone(time)); |
| 220 EXPECT_EQ(ASCIIToUTF16("April 2011"), TimeFormatMonthAndYear(time)); |
218 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 at 15:42:07"), | 221 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 at 15:42:07"), |
219 TimeFormatFriendlyDateAndTime(time)); | 222 TimeFormatFriendlyDateAndTime(time)); |
220 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"), | 223 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"), |
221 TimeFormatFriendlyDate(time)); | 224 TimeFormatFriendlyDate(time)); |
222 } | 225 } |
223 | 226 |
224 TEST(TimeFormattingTest, TimeDurationFormat) { | 227 TEST(TimeFormattingTest, TimeDurationFormat) { |
225 test::ScopedRestoreICUDefaultLocale restore_locale; | 228 test::ScopedRestoreICUDefaultLocale restore_locale; |
226 TimeDelta delta = TimeDelta::FromMinutes(15 * 60 + 42); | 229 TimeDelta delta = TimeDelta::FromMinutes(15 * 60 + 42); |
227 | 230 |
(...skipping 30 matching lines...) Expand all Loading... |
258 string16 fa_narrow = WideToUTF16( | 261 string16 fa_narrow = WideToUTF16( |
259 L"\x6f1\x6f5\x20\x633\x627\x639\x62a\x20\x6f4\x6f2\x20\x62f\x642\x6cc" | 262 L"\x6f1\x6f5\x20\x633\x627\x639\x62a\x20\x6f4\x6f2\x20\x62f\x642\x6cc" |
260 L"\x642\x647"); | 263 L"\x642\x647"); |
261 string16 fa_numeric = WideToUTF16(L"\x6f1\x6f5\x3a\x6f4\x6f2"); | 264 string16 fa_numeric = WideToUTF16(L"\x6f1\x6f5\x3a\x6f4\x6f2"); |
262 EXPECT_EQ(fa_wide, TimeDurationFormat(delta, DURATION_WIDTH_WIDE)); | 265 EXPECT_EQ(fa_wide, TimeDurationFormat(delta, DURATION_WIDTH_WIDE)); |
263 EXPECT_EQ(fa_short, TimeDurationFormat(delta, DURATION_WIDTH_SHORT)); | 266 EXPECT_EQ(fa_short, TimeDurationFormat(delta, DURATION_WIDTH_SHORT)); |
264 EXPECT_EQ(fa_narrow, TimeDurationFormat(delta, DURATION_WIDTH_NARROW)); | 267 EXPECT_EQ(fa_narrow, TimeDurationFormat(delta, DURATION_WIDTH_NARROW)); |
265 EXPECT_EQ(fa_numeric, TimeDurationFormat(delta, DURATION_WIDTH_NUMERIC)); | 268 EXPECT_EQ(fa_numeric, TimeDurationFormat(delta, DURATION_WIDTH_NUMERIC)); |
266 } | 269 } |
267 | 270 |
| 271 TEST(TimeFormattingTest, TimeIntervalFormat) { |
| 272 test::ScopedRestoreICUDefaultLocale restore_locale; |
| 273 i18n::SetICUDefaultLocale("en_US"); |
| 274 |
| 275 const Time::Exploded kTestIntervalEndTimeExploded = { |
| 276 2011, 5, 6, 28, // Sat, Apr 30, 2012 |
| 277 15, 42, 7, 0 // 15:42:07.000 |
| 278 }; |
| 279 |
| 280 Time begin_time; |
| 281 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &begin_time)); |
| 282 Time end_time; |
| 283 EXPECT_TRUE(Time::FromLocalExploded(kTestIntervalEndTimeExploded, &end_time)); |
| 284 |
| 285 EXPECT_EQ( |
| 286 WideToUTF16(L"Saturday, April 30 – Saturday, May 28"), |
| 287 DateIntervalFormat(begin_time, end_time, DATE_FORMAT_MONTH_WEEKDAY_DAY)); |
| 288 } |
| 289 |
268 } // namespace | 290 } // namespace |
269 } // namespace base | 291 } // namespace base |
OLD | NEW |