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

Unified Diff: base/i18n/time_formatting.cc

Issue 7054032: Fix ChromeOS clock menu so that it can show 12-hour clock in all locales. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed unnecessary use of PlatformTest. Created 9 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 e52bd22fba7b2d1c6e0a73397c90bf8994e9b69d..95d481e7190ea55f01fd6507e34163dec24f3db6 100644
--- a/base/i18n/time_formatting.cc
+++ b/base/i18n/time_formatting.cc
@@ -26,6 +26,26 @@ string16 TimeFormat(const icu::DateFormat* formatter,
static_cast<size_t>(date_string.length()));
}
+string16 TimeFormatWithoutAmPm(const icu::DateFormat* formatter,
+ const Time& time) {
+ DCHECK(formatter);
+ icu::UnicodeString time_string;
+
+ icu::FieldPosition ampm_field(icu::DateFormat::kAmPmField);
+ formatter->format(
+ static_cast<UDate>(time.ToDoubleT() * 1000), time_string, ampm_field);
+ int ampm_length = ampm_field.getEndIndex() - ampm_field.getBeginIndex();
+ if (ampm_length) {
+ int begin = ampm_field.getBeginIndex();
+ // Doesn't include any spacing before the field.
+ if (begin)
+ begin--;
+ time_string.removeBetween(begin, ampm_field.getEndIndex());
+ }
+ return string16(time_string.getBuffer(),
+ static_cast<size_t>(time_string.length()));
+}
+
} // namespace
namespace base {
@@ -39,11 +59,12 @@ string16 TimeFormatTimeOfDay(const Time& time) {
}
string16 TimeFormatTimeOfDayWithHourClockType(const Time& time,
- HourClockType type) {
+ HourClockType type,
+ AmPmClockType ampm) {
// Just redirect to the normal function if the default type matches the
// given type.
HourClockType default_type = GetHourClockType();
- if (default_type == type) {
+ if (default_type == type && (type == k24HourClock || ampm == kKeepAmPm)) {
return TimeFormatTimeOfDay(time);
}
@@ -63,7 +84,11 @@ string16 TimeFormatTimeOfDayWithHourClockType(const Time& time,
// Then, format the time using the generated pattern.
icu::SimpleDateFormat formatter(generated_pattern, status);
CHECK(U_SUCCESS(status));
- return TimeFormat(&formatter, time);
+ if (ampm == kKeepAmPm) {
+ return TimeFormat(&formatter, time);
+ } else {
+ return TimeFormatWithoutAmPm(&formatter, time);
+ }
}
string16 TimeFormatShortDate(const Time& time) {
« 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