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

Side by Side Diff: chrome/browser/resources/settings/device_page/night_light_slider.js

Issue 2951483003: [Night Light] CL9: Add localization for time's AM and PM (Closed)
Patch Set: Better helper function Created 3 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
« no previous file with comments | « chrome/browser/resources/settings/device_page/night_light_slider.html ('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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * night-light-slider is used to set the custom automatic schedule of the 7 * night-light-slider is used to set the custom automatic schedule of the
8 * Night Light feature, so that users can set their desired start and end 8 * Night Light feature, so that users can set their desired start and end
9 * times. 9 * times.
10 */ 10 */
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 * (which is the slider bar). 184 * (which is the slider bar).
185 * @param {HTMLDivElement} knob Either one of the two knobs. 185 * @param {HTMLDivElement} knob Either one of the two knobs.
186 * @return {number} 186 * @return {number}
187 * @private 187 * @private
188 */ 188 */
189 getKnobRatio_: function(knob) { 189 getKnobRatio_: function(knob) {
190 return parseFloat(knob.style.left) / this.$.sliderBar.offsetWidth; 190 return parseFloat(knob.style.left) / this.$.sliderBar.offsetWidth;
191 }, 191 },
192 192
193 /** 193 /**
194 * Pads the given number |num| with leading zeros such that its length as a 194 * Converts the time of day, given as |hour| and |minutes|, to its language-
195 * string is 2. 195 * sensitive time string representation.
196 * @param {number} num 196 * @param {number} hour The hour of the day (0 - 23).
197 * @param {number} minutes The minutes of the hour (0 - 59).
197 * @return {string} 198 * @return {string}
198 * @private 199 * @private
199 */ 200 */
200 pad2_: function(num) { 201 getLocaleTimeString_: function(hour, minutes) {
201 var s = String(num); 202 var d = new Date();
202 if (s.length == 2) 203 d.setHours(hour);
203 return s; 204 d.setMinutes(minutes);
205 d.setSeconds(0);
206 d.setMilliseconds(0);
204 207
205 return '0' + s; 208 return d.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
206 }, 209 },
207 210
208 /** 211 /**
209 * Converts the |offsetMinutes| value (which the number of minutes since 212 * Converts the |offsetMinutes| value (which the number of minutes since
210 * 00:00) to its string representation in the format 6:30 PM. 213 * 00:00) to its language-sensitive time string representation.
211 * @param {number} offsetMinutes The time of day represented as the number of 214 * @param {number} offsetMinutes The time of day represented as the number of
212 * minutes from 00:00. 215 * minutes from 00:00.
213 * @return {string} 216 * @return {string}
214 * @private 217 * @private
215 */ 218 */
216 offsetMinutesToTimeString_: function(offsetMinutes) { 219 offsetMinutesToTimeString_: function(offsetMinutes) {
217 // TODO(afakhry): Check if these values need to be localized.
218 var hour = Math.floor(offsetMinutes / 60); 220 var hour = Math.floor(offsetMinutes / 60);
219 var amPm = hour >= 12 ? ' PM' : ' AM';
220 hour %= 12;
221 hour = hour == 0 ? 12 : hour;
222 var minute = Math.floor(offsetMinutes % 60); 221 var minute = Math.floor(offsetMinutes % 60);
223 return hour + ':' + this.pad2_(minute) + amPm; 222
223 return this.getLocaleTimeString_(hour, minute);
224 }, 224 },
225 225
226 /** 226 /**
227 * Handles changes in the start and end times prefs. 227 * Handles changes in the start and end times prefs.
228 * @private 228 * @private
229 */ 229 */
230 customTimesChanged_: function() { 230 customTimesChanged_: function() {
231 var startOffsetMinutes = /** @type {number} */( 231 var startOffsetMinutes = /** @type {number} */(
232 this.getPref('ash.night_light.custom_start_time').value); 232 this.getPref('ash.night_light.custom_start_time').value);
233 this.startTime_ = this.offsetMinutesToTimeString_(startOffsetMinutes); 233 this.startTime_ = this.offsetMinutesToTimeString_(startOffsetMinutes);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 */ 440 */
441 onRightKey_: function(e) { 441 onRightKey_: function(e) {
442 e.preventDefault(); 442 e.preventDefault();
443 var knobPref = this.getFocusedKnobPrefPathIfAny_(); 443 var knobPref = this.getFocusedKnobPrefPathIfAny_();
444 if (!knobPref) 444 if (!knobPref)
445 return; 445 return;
446 446
447 this.incrementPref_(knobPref, 1); 447 this.incrementPref_(knobPref, 1);
448 }, 448 },
449 }); 449 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/device_page/night_light_slider.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698