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

Side by Side Diff: chrome/browser/chromeos/status/clock_menu_button.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, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/i18n/time_formatting_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/status/clock_menu_button.h" 5 #include "chrome/browser/chromeos/status/clock_menu_button.h"
6 6
7 #include "base/i18n/time_formatting.h" 7 #include "base/i18n/time_formatting.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 timer_.Start(base::TimeDelta::FromSeconds(seconds_left), this, 81 timer_.Start(base::TimeDelta::FromSeconds(seconds_left), this,
82 &ClockMenuButton::UpdateTextAndSetNextTimer); 82 &ClockMenuButton::UpdateTextAndSetNextTimer);
83 } 83 }
84 84
85 void ClockMenuButton::UpdateText() { 85 void ClockMenuButton::UpdateText() {
86 base::Time time(base::Time::Now()); 86 base::Time time(base::Time::Now());
87 // If the profie is present, check the use 24-hour clock preference. 87 // If the profie is present, check the use 24-hour clock preference.
88 const bool use_24hour_clock = 88 const bool use_24hour_clock =
89 host_->GetProfile() && 89 host_->GetProfile() &&
90 host_->GetProfile()->GetPrefs()->GetBoolean(prefs::kUse24HourClock); 90 host_->GetProfile()->GetPrefs()->GetBoolean(prefs::kUse24HourClock);
91 if (use_24hour_clock) { 91 SetText(UTF16ToWide(base::TimeFormatTimeOfDayWithHourClockType(
92 SetText(UTF16ToWide(base::TimeFormatTimeOfDayWithHourClockType( 92 time,
93 time, base::k24HourClock))); 93 use_24hour_clock ? base::k24HourClock : base::k12HourClock,
94 } else { 94 base::kDropAmPm)));
95 // Remove the am/pm field if it's present.
96 scoped_ptr<icu::DateFormat> formatter(
97 icu::DateFormat::createTimeInstance(icu::DateFormat::kShort));
98 icu::UnicodeString time_string;
99 icu::FieldPosition ampm_field(icu::DateFormat::kAmPmField);
100 formatter->format(
101 static_cast<UDate>(time.ToDoubleT() * 1000), time_string, ampm_field);
102 int ampm_length = ampm_field.getEndIndex() - ampm_field.getBeginIndex();
103 if (ampm_length) {
104 int begin = ampm_field.getBeginIndex();
105 // Doesn't include any spacing before the field.
106 if (begin)
107 begin--;
108 time_string.removeBetween(begin, ampm_field.getEndIndex());
109 }
110 string16 time_string16 =
111 string16(time_string.getBuffer(),
112 static_cast<size_t>(time_string.length()));
113 SetText(UTF16ToWide(time_string16));
114 }
115 SetTooltipText(UTF16ToWide(base::TimeFormatShortDate(time))); 95 SetTooltipText(UTF16ToWide(base::TimeFormatShortDate(time)));
116 SchedulePaint(); 96 SchedulePaint();
117 } 97 }
118 98
119 // ClockMenuButton, NotificationObserver implementation: 99 // ClockMenuButton, NotificationObserver implementation:
120 100
121 void ClockMenuButton::Observe(NotificationType type, 101 void ClockMenuButton::Observe(NotificationType type,
122 const NotificationSource& source, 102 const NotificationSource& source,
123 const NotificationDetails& details) { 103 const NotificationDetails& details) {
124 if (type == NotificationType::PREF_CHANGED) { 104 if (type == NotificationType::PREF_CHANGED) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 const string16 clock_open_options_label = 191 const string16 clock_open_options_label =
212 l10n_util::GetStringUTF16(IDS_STATUSBAR_CLOCK_OPEN_OPTIONS_DIALOG); 192 l10n_util::GetStringUTF16(IDS_STATUSBAR_CLOCK_OPEN_OPTIONS_DIALOG);
213 menu_->AppendMenuItemWithLabel( 193 menu_->AppendMenuItemWithLabel(
214 CLOCK_OPEN_OPTIONS_ITEM, 194 CLOCK_OPEN_OPTIONS_ITEM,
215 UTF16ToWide(clock_open_options_label)); 195 UTF16ToWide(clock_open_options_label));
216 } 196 }
217 } 197 }
218 } 198 }
219 199
220 } // namespace chromeos 200 } // namespace chromeos
OLDNEW
« no previous file with comments | « base/i18n/time_formatting_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698