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

Unified Diff: base/i18n/time_formatting.cc

Issue 1951493002: Fix i18n number formats in tray power displays (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switch unit test from Bengali to Persian for Android (and merge) Created 4 years, 7 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 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
« 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