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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/settings/device_page/night_light_slider.js
diff --git a/chrome/browser/resources/settings/device_page/night_light_slider.js b/chrome/browser/resources/settings/device_page/night_light_slider.js
index 64e3aa5ac0648791c9254318c4054f488fe1015d..787786eda790f786c3df49161540fb3b3140d7fa 100644
--- a/chrome/browser/resources/settings/device_page/night_light_slider.js
+++ b/chrome/browser/resources/settings/device_page/night_light_slider.js
@@ -191,36 +191,36 @@ Polymer({
},
/**
- * Pads the given number |num| with leading zeros such that its length as a
- * string is 2.
- * @param {number} num
+ * Converts the time of day, given as |hour| and |minutes|, to its language-
+ * sensitive time string representation.
+ * @param {number} hour The hour of the day (0 - 23).
+ * @param {number} minutes The minutes of the hour (0 - 59).
* @return {string}
* @private
*/
- pad2_: function(num) {
- var s = String(num);
- if (s.length == 2)
- return s;
-
- return '0' + s;
+ getLocaleTimeString_: function(hour, minutes) {
+ var d = new Date();
+ d.setHours(hour);
+ d.setMinutes(minutes);
+ d.setSeconds(0);
+ d.setMilliseconds(0);
+
+ return d.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
},
/**
* Converts the |offsetMinutes| value (which the number of minutes since
- * 00:00) to its string representation in the format 6:30 PM.
+ * 00:00) to its language-sensitive time string representation.
* @param {number} offsetMinutes The time of day represented as the number of
* minutes from 00:00.
* @return {string}
* @private
*/
offsetMinutesToTimeString_: function(offsetMinutes) {
- // TODO(afakhry): Check if these values need to be localized.
var hour = Math.floor(offsetMinutes / 60);
- var amPm = hour >= 12 ? ' PM' : ' AM';
- hour %= 12;
- hour = hour == 0 ? 12 : hour;
var minute = Math.floor(offsetMinutes % 60);
- return hour + ':' + this.pad2_(minute) + amPm;
+
+ return this.getLocaleTimeString_(hour, minute);
},
/**
« 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