Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: base/i18n/time_formatting_unittest.cc

Issue 2570253002: [MD History] Fix toolbar dates in grouped mode. (Closed)
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/i18n/time_formatting.cc ('k') | chrome/browser/resources/history/externs.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 EXPECT_EQ(ASCIIToUTF16("15 hours, 42 minutes, 0 seconds"), 310 EXPECT_EQ(ASCIIToUTF16("15 hours, 42 minutes, 0 seconds"),
308 TimeDurationFormatWithSeconds(delta, DURATION_WIDTH_WIDE)); 311 TimeDurationFormatWithSeconds(delta, DURATION_WIDTH_WIDE));
309 EXPECT_EQ(ASCIIToUTF16("15 hr, 42 min, 0 sec"), 312 EXPECT_EQ(ASCIIToUTF16("15 hr, 42 min, 0 sec"),
310 TimeDurationFormatWithSeconds(delta, DURATION_WIDTH_SHORT)); 313 TimeDurationFormatWithSeconds(delta, DURATION_WIDTH_SHORT));
311 EXPECT_EQ(ASCIIToUTF16("15h 42m 0s"), 314 EXPECT_EQ(ASCIIToUTF16("15h 42m 0s"),
312 TimeDurationFormatWithSeconds(delta, DURATION_WIDTH_NARROW)); 315 TimeDurationFormatWithSeconds(delta, DURATION_WIDTH_NARROW));
313 EXPECT_EQ(ASCIIToUTF16("15:42:00"), 316 EXPECT_EQ(ASCIIToUTF16("15:42:00"),
314 TimeDurationFormatWithSeconds(delta, DURATION_WIDTH_NUMERIC)); 317 TimeDurationFormatWithSeconds(delta, DURATION_WIDTH_NUMERIC));
315 } 318 }
316 319
320 TEST(TimeFormattingTest, TimeIntervalFormat) {
321 test::ScopedRestoreICUDefaultLocale restore_locale;
322 i18n::SetICUDefaultLocale("en_US");
323
324 const Time::Exploded kTestIntervalEndTimeExploded = {
325 2011, 5, 6, 28, // Sat, Apr 30, 2012
326 15, 42, 7, 0 // 15:42:07.000
327 };
328
329 Time begin_time;
330 EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &begin_time));
331 Time end_time;
332 EXPECT_TRUE(Time::FromLocalExploded(kTestIntervalEndTimeExploded, &end_time));
333
334 EXPECT_EQ(
335 WideToUTF16(L"Saturday, April 30 – Saturday, May 28"),
336 DateIntervalFormat(begin_time, end_time, DATE_FORMAT_MONTH_WEEKDAY_DAY));
337 }
338
317 } // namespace 339 } // namespace
318 } // namespace base 340 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/time_formatting.cc ('k') | chrome/browser/resources/history/externs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698