mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-27 01:27:30 +09:00
Bug 1382175 - Fix time picker step and min/max regressions
This commit is contained in:
parent
7f3ec297c9
commit
6993cdbd88
2 changed files with 12 additions and 26 deletions
|
|
@ -14,7 +14,7 @@
|
||||||
* {
|
* {
|
||||||
* {Date} min
|
* {Date} min
|
||||||
* {Date} max
|
* {Date} max
|
||||||
* {Number} stepInMs
|
* {Number} step
|
||||||
* {String} format: Either "12" or "24"
|
* {String} format: Either "12" or "24"
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
@ -286,15 +286,15 @@ function TimeKeeper(props) {
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
_getSteps(startValue, endValue, minStep, formatter) {
|
_getSteps(startValue, endValue, minStep, formatter) {
|
||||||
const { min, max, stepInMs } = this.props;
|
const { min, max, step } = this.props;
|
||||||
// The timeStep should be big enough so that there won't be
|
// The timeStep should be big enough so that there won't be
|
||||||
// duplications. Ex: minimum step for minute should be 60000ms,
|
// duplications. Ex: minimum step for minute should be 60000ms,
|
||||||
// if smaller than that, next step might return the same minute.
|
// if smaller than that, next step might return the same minute.
|
||||||
const timeStep = Math.max(minStep, stepInMs);
|
const timeStep = Math.max(minStep, step);
|
||||||
|
|
||||||
// Make sure the starting point and end point is not off step
|
// Make sure the starting point and end point is not off step
|
||||||
let time = min.valueOf() + Math.ceil((startValue - min.valueOf()) / timeStep) * timeStep;
|
let time = min.valueOf() + Math.ceil((startValue - min.valueOf()) / timeStep) * timeStep;
|
||||||
let maxValue = min.valueOf() + Math.floor((max.valueOf() - min.valueOf()) / stepInMs) * stepInMs;
|
let maxValue = min.valueOf() + Math.floor((max.valueOf() - min.valueOf()) / step) * step;
|
||||||
let steps = [];
|
let steps = [];
|
||||||
|
|
||||||
// Increment by timeStep until reaching the end of the range.
|
// Increment by timeStep until reaching the end of the range.
|
||||||
|
|
@ -410,9 +410,9 @@ function TimeKeeper(props) {
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
_isOffStep(time) {
|
_isOffStep(time) {
|
||||||
const { min, stepInMs } = this.props;
|
const { min, step } = this.props;
|
||||||
|
|
||||||
return (time.valueOf() - min.valueOf()) % stepInMs != 0;
|
return (time.valueOf() - min.valueOf()) % step != 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ function TimePicker(context) {
|
||||||
const debug = 0 ? console.log.bind(console, "[timepicker]") : function() {};
|
const debug = 0 ? console.log.bind(console, "[timepicker]") : function() {};
|
||||||
|
|
||||||
const DAY_PERIOD_IN_HOURS = 12,
|
const DAY_PERIOD_IN_HOURS = 12,
|
||||||
SECOND_IN_MS = 1000,
|
|
||||||
MINUTE_IN_MS = 60000,
|
|
||||||
DAY_IN_MS = 86400000;
|
DAY_IN_MS = 86400000;
|
||||||
|
|
||||||
TimePicker.prototype = {
|
TimePicker.prototype = {
|
||||||
|
|
@ -24,9 +22,9 @@ function TimePicker(context) {
|
||||||
* {
|
* {
|
||||||
* {Number} hour [optional]: Hour in 24 hours format (0~23), default is current hour
|
* {Number} hour [optional]: Hour in 24 hours format (0~23), default is current hour
|
||||||
* {Number} minute [optional]: Minute (0~59), default is current minute
|
* {Number} minute [optional]: Minute (0~59), default is current minute
|
||||||
* {String} min [optional]: Minimum time, in 24 hours format. ex: "05:45"
|
* {Number} min: Minimum time, in ms
|
||||||
* {String} max [optional]: Maximum time, in 24 hours format. ex: "23:00"
|
* {Number} max: Maximum time, in ms
|
||||||
* {Number} step [optional]: Step size in minutes. Default is 60.
|
* {Number} step: Step size in ms
|
||||||
* {String} format [optional]: "12" for 12 hours, "24" for 24 hours format
|
* {String} format [optional]: "12" for 12 hours, "24" for 24 hours format
|
||||||
* {String} locale [optional]: User preferred locale
|
* {String} locale [optional]: User preferred locale
|
||||||
* }
|
* }
|
||||||
|
|
@ -51,11 +49,10 @@ function TimePicker(context) {
|
||||||
let timerHour = hour == undefined ? now.getHours() : hour;
|
let timerHour = hour == undefined ? now.getHours() : hour;
|
||||||
let timerMinute = minute == undefined ? now.getMinutes() : minute;
|
let timerMinute = minute == undefined ? now.getMinutes() : minute;
|
||||||
|
|
||||||
// The spec defines 1 step == 1 second, need to convert to ms for timekeeper
|
|
||||||
let timeKeeper = new TimeKeeper({
|
let timeKeeper = new TimeKeeper({
|
||||||
min: this._parseTimeString(min) || new Date(0),
|
min: new Date(Number.isNaN(min) ? 0 : min),
|
||||||
max: this._parseTimeString(max) || new Date(DAY_IN_MS - 1),
|
max: new Date(Number.isNaN(max) ? DAY_IN_MS - 1 : max),
|
||||||
stepInMs: step ? step * SECOND_IN_MS : MINUTE_IN_MS,
|
step,
|
||||||
format: format || "12"
|
format: format || "12"
|
||||||
});
|
});
|
||||||
timeKeeper.setState({ hour: timerHour, minute: timerMinute });
|
timeKeeper.setState({ hour: timerHour, minute: timerMinute });
|
||||||
|
|
@ -63,17 +60,6 @@ function TimePicker(context) {
|
||||||
this.state = { timeKeeper };
|
this.state = { timeKeeper };
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a time string from DOM attribute to a date object.
|
|
||||||
*
|
|
||||||
* @param {String} timeString: (ex. "10:30", "23:55", "12:34:56.789")
|
|
||||||
* @return {Date/Boolean} Date object or false if date is invalid.
|
|
||||||
*/
|
|
||||||
_parseTimeString(timeString) {
|
|
||||||
let time = new Date("1970-01-01T" + timeString + "Z");
|
|
||||||
return time.toString() == "Invalid Date" ? false : time;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initalize the spinner components.
|
* Initalize the spinner components.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue