| 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 {
|
|
|