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

Unified Diff: base/i18n/time_formatting_unittest.cc

Issue 1641513004: Update //base to chromium 9659b08ea5a34f889dc4166217f438095ddc10d2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/i18n/time_formatting.cc ('k') | base/ios/crb_protocol_observers_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/i18n/time_formatting_unittest.cc
diff --git a/base/i18n/time_formatting_unittest.cc b/base/i18n/time_formatting_unittest.cc
index df0c1ed5ea1ec121b7e7d77b1cfbf1e89e36f088..93856280d9a94dc24e8188320360c6a8874b0ec8 100644
--- a/base/i18n/time_formatting_unittest.cc
+++ b/base/i18n/time_formatting_unittest.cc
@@ -12,6 +12,7 @@
#include "third_party/icu/source/common/unicode/uversion.h"
#include "third_party/icu/source/i18n/unicode/calendar.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
+#include "third_party/icu/source/i18n/unicode/tzfmt.h"
namespace base {
namespace {
@@ -21,10 +22,19 @@ const Time::Exploded kTestDateTimeExploded = {
15, 42, 7, 0 // 15:42:07.000
};
-base::string16 GetShortTimeZone() {
+// Returns difference between the local time and GMT formatted as string.
+// This function gets |time| because the difference depends on time,
+// see https://en.wikipedia.org/wiki/Daylight_saving_time for details.
+base::string16 GetShortTimeZone(const Time& time) {
+ UErrorCode status = U_ZERO_ERROR;
scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault());
+ scoped_ptr<icu::TimeZoneFormat> zone_formatter(
+ icu::TimeZoneFormat::createInstance(icu::Locale::getDefault(), status));
+ EXPECT_TRUE(U_SUCCESS(status));
icu::UnicodeString name;
- zone->getDisplayName(true, icu::TimeZone::SHORT, name);
+ zone_formatter->format(UTZFMT_STYLE_SPECIFIC_SHORT, *zone,
+ static_cast<UDate>(time.ToDoubleT() * 1000), name,
+ nullptr);
return base::string16(name.getBuffer(), name.length());
}
@@ -37,9 +47,11 @@ TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault12h) {
string16 clock24h(ASCIIToUTF16("15:42"));
string16 clock12h_pm(ASCIIToUTF16("3:42 PM"));
string16 clock12h(ASCIIToUTF16("3:42"));
+ string16 clock24h_millis(ASCIIToUTF16("15:42:07.000"));
// The default is 12h clock.
EXPECT_EQ(clock12h_pm, TimeFormatTimeOfDay(time));
+ EXPECT_EQ(clock24h_millis, TimeFormatTimeOfDayWithMilliseconds(time));
EXPECT_EQ(k12HourClock, GetHourClockType());
// k{Keep,Drop}AmPm should not affect for 24h clock.
EXPECT_EQ(clock24h,
@@ -70,9 +82,11 @@ TEST(TimeFormattingTest, TimeFormatTimeOfDayDefault24h) {
string16 clock24h(ASCIIToUTF16("15:42"));
string16 clock12h_pm(ASCIIToUTF16("3:42 pm"));
string16 clock12h(ASCIIToUTF16("3:42"));
+ string16 clock24h_millis(ASCIIToUTF16("15:42:07.000"));
// The default is 24h clock.
EXPECT_EQ(clock24h, TimeFormatTimeOfDay(time));
+ EXPECT_EQ(clock24h_millis, TimeFormatTimeOfDayWithMilliseconds(time));
EXPECT_EQ(k24HourClock, GetHourClockType());
// k{Keep,Drop}AmPm should not affect for 24h clock.
EXPECT_EQ(clock24h,
@@ -139,7 +153,7 @@ TEST(TimeFormattingTest, TimeFormatDateUS) {
EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM"),
TimeFormatShortDateAndTime(time));
- EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM ") + GetShortTimeZone(),
+ EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM ") + GetShortTimeZone(time),
TimeFormatShortDateAndTimeWithTimeZone(time));
EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"),
@@ -160,7 +174,7 @@ TEST(TimeFormattingTest, TimeFormatDateGB) {
EXPECT_EQ(ASCIIToUTF16("30/04/2011"), TimeFormatShortDateNumeric(time));
EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07"),
TimeFormatShortDateAndTime(time));
- EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(),
+ EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(time),
TimeFormatShortDateAndTimeWithTimeZone(time));
EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 at 15:42:07"),
TimeFormatFriendlyDateAndTime(time));
« no previous file with comments | « base/i18n/time_formatting.cc ('k') | base/ios/crb_protocol_observers_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698