| Index: base/i18n/time_formatting.cc
|
| diff --git a/base/i18n/time_formatting.cc b/base/i18n/time_formatting.cc
|
| index 666abd44dd6c03decc9ad5fce4228401fa31a31f..024b86510b5a8260565dbd02eaaa376949de22a3 100644
|
| --- a/base/i18n/time_formatting.cc
|
| +++ b/base/i18n/time_formatting.cc
|
| @@ -13,6 +13,8 @@
|
| #include "base/time/time.h"
|
| #include "third_party/icu/source/i18n/unicode/datefmt.h"
|
| #include "third_party/icu/source/i18n/unicode/dtptngen.h"
|
| +#include "third_party/icu/source/i18n/unicode/fmtable.h"
|
| +#include "third_party/icu/source/i18n/unicode/measfmt.h"
|
| #include "third_party/icu/source/i18n/unicode/smpdtfmt.h"
|
|
|
| namespace base {
|
| @@ -68,6 +70,17 @@ icu::SimpleDateFormat CreateSimpleDateFormatter(const char* pattern) {
|
| return formatter;
|
| }
|
|
|
| +UMeasureFormatWidth DurationWidthToMeasureWidth(DurationFormatWidth width) {
|
| + switch (width) {
|
| + case DURATION_WIDTH_WIDE: return UMEASFMT_WIDTH_WIDE;
|
| + case DURATION_WIDTH_SHORT: return UMEASFMT_WIDTH_SHORT;
|
| + case DURATION_WIDTH_NARROW: return UMEASFMT_WIDTH_NARROW;
|
| + case DURATION_WIDTH_NUMERIC: return UMEASFMT_WIDTH_NUMERIC;
|
| + }
|
| + NOTREACHED();
|
| + return UMEASFMT_WIDTH_COUNT;
|
| +}
|
| +
|
| } // namespace
|
|
|
| string16 TimeFormatTimeOfDay(const Time& time) {
|
| @@ -140,6 +153,24 @@ string16 TimeFormatFriendlyDate(const Time& time) {
|
| return TimeFormat(formatter.get(), time);
|
| }
|
|
|
| +string16 TimeDurationFormat(const TimeDelta& time,
|
| + const DurationFormatWidth width) {
|
| + UErrorCode status = U_ZERO_ERROR;
|
| + const int total_minutes = static_cast<int>(time.InSecondsF() / 60 + 0.5);
|
| + int hours = total_minutes / 60;
|
| + int minutes = total_minutes % 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::MeasureFormat measure_format(icu::Locale::getDefault(), u_width, status);
|
| + icu::UnicodeString formatted;
|
| + icu::FieldPosition ignore(icu::FieldPosition::DONT_CARE);
|
| + measure_format.formatMeasures(measures, 2, 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
|
|
|