Chromium Code Reviews| Index: base/i18n/time_formatting.cc |
| diff --git a/base/i18n/time_formatting.cc b/base/i18n/time_formatting.cc |
| index 024b86510b5a8260565dbd02eaaa376949de22a3..844fefa2662cc47f1490573c03ef2fd1b977119a 100644 |
| --- a/base/i18n/time_formatting.cc |
| +++ b/base/i18n/time_formatting.cc |
| @@ -171,6 +171,27 @@ string16 TimeDurationFormat(const TimeDelta& time, |
| return base::string16(formatted.getBuffer(), formatted.length()); |
| } |
| +string16 TimeDurationWFormatWithSecondPrecison( |
| + const TimeDelta& time, |
| + const DurationFormatWidth width) { |
| + UErrorCode status = U_ZERO_ERROR; |
| + const int64_t total_seconds = time.InSeconds(); |
|
brucedawson
2016/12/19 21:51:05
Consider rounding to nearest as in TimeDurationFor
chengx
2016/12/20 00:51:12
Done.
|
| + int hours = total_seconds / 3600; |
|
brucedawson
2016/12/19 21:51:05
Why no 'const' here? It seems inconsistent with to
chengx
2016/12/20 00:51:12
In icu::Measure, actually its first parameter is c
|
| + int minutes = (total_seconds - hours * 3600) / 60; |
| + int seconds = total_seconds % 60; |
| + UMeasureFormatWidth u_width = DurationWidthToMeasureWidth(width); |
| + |
| + const icu::Measure measures[] = { |
| + icu::Measure(hours, icu::MeasureUnit::createHour(status), status), |
| + icu::Measure(minutes, icu::MeasureUnit::createMinute(status), status), |
| + icu::Measure(seconds, icu::MeasureUnit::createSecond(status), status)}; |
| + icu::MeasureFormat measure_format(icu::Locale::getDefault(), u_width, status); |
| + icu::UnicodeString formatted; |
| + icu::FieldPosition ignore(icu::FieldPosition::DONT_CARE); |
| + measure_format.formatMeasures(measures, 3, formatted, ignore, status); |
| + return base::string16(formatted.getBuffer(), formatted.length()); |
| +} |
| + |
| HourClockType GetHourClockType() { |
| // TODO(satorux,jshin): Rework this with ures_getByKeyWithFallback() |
| // once it becomes public. The short time format can be found at |