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

Unified Diff: base/i18n/time_formatting.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.h ('k') | base/i18n/time_formatting_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/i18n/time_formatting.cc
diff --git a/base/i18n/time_formatting.cc b/base/i18n/time_formatting.cc
index 15b34a31f917f0042be0513fd09f5580e38ff41a..55121115fa5387e5a9d0e629aa26ec2e9da539da 100644
--- a/base/i18n/time_formatting.cc
+++ b/base/i18n/time_formatting.cc
@@ -45,6 +45,26 @@ string16 TimeFormatWithoutAmPm(const icu::DateFormat* formatter,
static_cast<size_t>(time_string.length()));
}
+icu::SimpleDateFormat CreateSimpleDateFormatter(const char* pattern) {
+ // Generate a locale-dependent format pattern. The generator will take
+ // care of locale-dependent formatting issues like which separator to
+ // use (some locales use '.' instead of ':'), and where to put the am/pm
+ // marker.
+ UErrorCode status = U_ZERO_ERROR;
+ scoped_ptr<icu::DateTimePatternGenerator> generator(
+ icu::DateTimePatternGenerator::createInstance(status));
+ DCHECK(U_SUCCESS(status));
+ icu::UnicodeString generated_pattern =
+ generator->getBestPattern(icu::UnicodeString(pattern), status);
+ DCHECK(U_SUCCESS(status));
+
+ // Then, format the time using the generated pattern.
+ icu::SimpleDateFormat formatter(generated_pattern, status);
+ DCHECK(U_SUCCESS(status));
+
+ return formatter;
+}
+
} // namespace
string16 TimeFormatTimeOfDay(const Time& time) {
@@ -55,6 +75,11 @@ string16 TimeFormatTimeOfDay(const Time& time) {
return TimeFormat(formatter.get(), time);
}
+string16 TimeFormatTimeOfDayWithMilliseconds(const Time& time) {
+ icu::SimpleDateFormat formatter = CreateSimpleDateFormatter("HmsSSS");
+ return TimeFormatWithoutAmPm(&formatter, time);
+}
+
string16 TimeFormatTimeOfDayWithHourClockType(const Time& time,
HourClockType type,
AmPmClockType ampm) {
@@ -65,22 +90,9 @@ string16 TimeFormatTimeOfDayWithHourClockType(const Time& time,
return TimeFormatTimeOfDay(time);
}
- // Generate a locale-dependent format pattern. The generator will take
- // care of locale-dependent formatting issues like which separator to
- // use (some locales use '.' instead of ':'), and where to put the am/pm
- // marker.
- UErrorCode status = U_ZERO_ERROR;
- scoped_ptr<icu::DateTimePatternGenerator> generator(
- icu::DateTimePatternGenerator::createInstance(status));
- DCHECK(U_SUCCESS(status));
const char* base_pattern = (type == k12HourClock ? "ahm" : "Hm");
- icu::UnicodeString generated_pattern =
- generator->getBestPattern(icu::UnicodeString(base_pattern), status);
- DCHECK(U_SUCCESS(status));
+ icu::SimpleDateFormat formatter = CreateSimpleDateFormatter(base_pattern);
- // Then, format the time using the generated pattern.
- icu::SimpleDateFormat formatter(generated_pattern, status);
- DCHECK(U_SUCCESS(status));
if (ampm == kKeepAmPm) {
return TimeFormat(&formatter, time);
} else {
« no previous file with comments | « base/i18n/time_formatting.h ('k') | base/i18n/time_formatting_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698