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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07"), | 209 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07"), |
210 TimeFormatShortDateAndTime(time)); | 210 TimeFormatShortDateAndTime(time)); |
211 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(time), | 211 EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(time), |
212 TimeFormatShortDateAndTimeWithTimeZone(time)); | 212 TimeFormatShortDateAndTimeWithTimeZone(time)); |
213 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 at 15:42:07"), | 213 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 at 15:42:07"), |
214 TimeFormatFriendlyDateAndTime(time)); | 214 TimeFormatFriendlyDateAndTime(time)); |
215 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"), | 215 EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"), |
216 TimeFormatFriendlyDate(time)); | 216 TimeFormatFriendlyDate(time)); |
217 } | 217 } |
218 | 218 |
| 219 TEST(TimeFormattingTest, TimeDurationFormat) { |
| 220 test::ScopedRestoreICUDefaultLocale restore_locale; |
| 221 TimeDelta delta = TimeDelta::FromMinutes(15 * 60 + 42); |
| 222 |
| 223 // US English. |
| 224 i18n::SetICUDefaultLocale("en_US"); |
| 225 EXPECT_EQ(ASCIIToUTF16("15 hours, 42 minutes"), |
| 226 TimeDurationFormat(delta, DURATION_WIDTH_WIDE)); |
| 227 EXPECT_EQ(ASCIIToUTF16("15 hr, 42 min"), |
| 228 TimeDurationFormat(delta, DURATION_WIDTH_SHORT)); |
| 229 EXPECT_EQ(ASCIIToUTF16("15h 42m"), |
| 230 TimeDurationFormat(delta, DURATION_WIDTH_NARROW)); |
| 231 EXPECT_EQ(ASCIIToUTF16("15:42"), |
| 232 TimeDurationFormat(delta, DURATION_WIDTH_NUMERIC)); |
| 233 |
| 234 // Danish, with Latin alphabet but different abbreviations and punctuation. |
| 235 i18n::SetICUDefaultLocale("da"); |
| 236 EXPECT_EQ(ASCIIToUTF16("15 timer og 42 minutter"), |
| 237 TimeDurationFormat(delta, DURATION_WIDTH_WIDE)); |
| 238 EXPECT_EQ(ASCIIToUTF16("15 t og 42 min."), |
| 239 TimeDurationFormat(delta, DURATION_WIDTH_SHORT)); |
| 240 EXPECT_EQ(ASCIIToUTF16("15 t og 42 min"), |
| 241 TimeDurationFormat(delta, DURATION_WIDTH_NARROW)); |
| 242 EXPECT_EQ(ASCIIToUTF16("15.42"), |
| 243 TimeDurationFormat(delta, DURATION_WIDTH_NUMERIC)); |
| 244 |
| 245 // Persian, with non-Arabic numbers. |
| 246 i18n::SetICUDefaultLocale("fa"); |
| 247 string16 fa_wide = WideToUTF16( |
| 248 L"\x6f1\x6f5\x20\x633\x627\x639\x62a\x20\x648\x20\x6f4\x6f2\x20\x62f\x642" |
| 249 L"\x6cc\x642\x647"); |
| 250 string16 fa_short = WideToUTF16( |
| 251 L"\x6f1\x6f5\x20\x633\x627\x639\x62a\x60c\x200f\x20\x6f4\x6f2\x20\x62f" |
| 252 L"\x642\x6cc\x642\x647"); |
| 253 string16 fa_narrow = WideToUTF16( |
| 254 L"\x6f1\x6f5\x20\x633\x627\x639\x62a\x20\x6f4\x6f2\x20\x62f\x642\x6cc" |
| 255 L"\x642\x647"); |
| 256 string16 fa_numeric = WideToUTF16(L"\x6f1\x6f5\x3a\x6f4\x6f2"); |
| 257 EXPECT_EQ(fa_wide, TimeDurationFormat(delta, DURATION_WIDTH_WIDE)); |
| 258 EXPECT_EQ(fa_short, TimeDurationFormat(delta, DURATION_WIDTH_SHORT)); |
| 259 EXPECT_EQ(fa_narrow, TimeDurationFormat(delta, DURATION_WIDTH_NARROW)); |
| 260 EXPECT_EQ(fa_numeric, TimeDurationFormat(delta, DURATION_WIDTH_NUMERIC)); |
| 261 } |
| 262 |
219 } // namespace | 263 } // namespace |
220 } // namespace base | 264 } // namespace base |
OLD | NEW |