OLD | NEW |
---|---|
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 Loading... | |
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 | |
195 * string is 2. | |
196 * @param {number} num | |
197 * @return {string} | |
198 * @private | |
199 */ | |
200 pad2_: function(num) { | |
201 var s = String(num); | |
202 if (s.length == 2) | |
203 return s; | |
204 | |
205 return '0' + s; | |
206 }, | |
207 | |
208 /** | |
209 * Converts the |offsetMinutes| value (which the number of minutes since | 194 * Converts the |offsetMinutes| value (which the number of minutes since |
210 * 00:00) to its string representation in the format 6:30 PM. | 195 * 00:00) to its language-sensitive time string representation. |
211 * @param {number} offsetMinutes The time of day represented as the number of | 196 * @param {number} offsetMinutes The time of day represented as the number of |
212 * minutes from 00:00. | 197 * minutes from 00:00. |
213 * @return {string} | 198 * @return {string} |
214 * @private | 199 * @private |
215 */ | 200 */ |
216 offsetMinutesToTimeString_: function(offsetMinutes) { | 201 offsetMinutesToTimeString_: function(offsetMinutes) { |
217 // TODO(afakhry): Check if these values need to be localized. | |
218 var hour = Math.floor(offsetMinutes / 60); | 202 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); | 203 var minute = Math.floor(offsetMinutes % 60); |
223 return hour + ':' + this.pad2_(minute) + amPm; | 204 |
205 var d = new Date(Date.now()); | |
stevenjb
2017/06/20 17:25:56
I think this is the same as Date() ?
afakhry
2017/06/20 18:10:34
Done.
| |
206 d.setHours(hour); | |
207 d.setMinutes(minute); | |
208 d.setSeconds(0); | |
209 d.setMilliseconds(0); | |
210 | |
211 return d.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'}); | |
224 }, | 212 }, |
225 | 213 |
226 /** | 214 /** |
227 * Handles changes in the start and end times prefs. | 215 * Handles changes in the start and end times prefs. |
228 * @private | 216 * @private |
229 */ | 217 */ |
230 customTimesChanged_: function() { | 218 customTimesChanged_: function() { |
231 var startOffsetMinutes = /** @type {number} */( | 219 var startOffsetMinutes = /** @type {number} */( |
232 this.getPref('ash.night_light.custom_start_time').value); | 220 this.getPref('ash.night_light.custom_start_time').value); |
233 this.startTime_ = this.offsetMinutesToTimeString_(startOffsetMinutes); | 221 this.startTime_ = this.offsetMinutesToTimeString_(startOffsetMinutes); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 */ | 428 */ |
441 onRightKey_: function(e) { | 429 onRightKey_: function(e) { |
442 e.preventDefault(); | 430 e.preventDefault(); |
443 var knobPref = this.getFocusedKnobPrefPathIfAny_(); | 431 var knobPref = this.getFocusedKnobPrefPathIfAny_(); |
444 if (!knobPref) | 432 if (!knobPref) |
445 return; | 433 return; |
446 | 434 |
447 this.incrementPref_(knobPref, 1); | 435 this.incrementPref_(knobPref, 1); |
448 }, | 436 }, |
449 }); | 437 }); |
OLD | NEW |