提交 6582eba1 编写于 作者: S sushuang

Fix parseDate, consider DST

上级 8d6b6776
......@@ -77,7 +77,7 @@ define(function (require) {
// If there are no data and extent are [Infinity, -Infinity]
if (extent[1] === -Infinity && extent[0] === Infinity) {
var d = new Date();
extent[1] = new Date(d.getFullYear(), d.getMonth(), d.getDate());
extent[1] = +new Date(d.getFullYear(), d.getMonth(), d.getDate());
extent[0] = extent[1] - ONE_DAY;
}
......@@ -98,8 +98,6 @@ define(function (require) {
* @override
*/
niceTicks: function (approxTickNum, minInterval, maxInterval) {
var timezoneOffset = this.getSetting('useUTC')
? 0 : numberUtil.getTimezoneOffset() * 60 * 1000;
approxTickNum = approxTickNum || 10;
var extent = this._extent;
......@@ -129,9 +127,11 @@ define(function (require) {
interval *= yearStep;
}
var timezoneOffset = this.getSetting('useUTC')
? 0 : (new Date(+extent[0] || +extent[1])).getTimezoneOffset() * 60 * 1000;
var niceExtent = [
Math.round(mathCeil((extent[0] - timezoneOffset) / interval) * interval + timezoneOffset),
Math.round(mathFloor((extent[1] - timezoneOffset)/ interval) * interval + timezoneOffset)
Math.round(mathFloor((extent[1] - timezoneOffset) / interval) * interval + timezoneOffset)
];
scaleHelper.fixExtent(niceExtent, extent);
......
......@@ -273,11 +273,14 @@ define(function (require) {
var TIME_REG = /^(?:(\d{4})(?:[-\/](\d{1,2})(?:[-\/](\d{1,2})(?:[T ](\d{1,2})(?::(\d\d)(?::(\d\d)(?:[.,](\d+))?)?)?(Z|[\+\-]\d\d:?\d\d)?)?)?)?)?$/; // jshint ignore:line
/**
* Consider DST, it is incorrect to provide a method `getTimezoneOffset`
* without time specified. So this method is removed.
*
* @return {number} in minutes
*/
number.getTimezoneOffset = function () {
return (new Date()).getTimezoneOffset();
};
// number.getTimezoneOffset = function () {
// return (new Date()).getTimezoneOffset();
// };
/**
* @param {string|Date|number} value These values can be accepted:
......@@ -311,24 +314,42 @@ define(function (require) {
return new Date(NaN);
}
var timezoneOffset = number.getTimezoneOffset();
var timeOffset = !match[8]
? 0
: match[8].toUpperCase() === 'Z'
? timezoneOffset
: +match[8].slice(0, 3) * 60 + timezoneOffset;
// match[n] can only be string or undefined.
// But take care of '12' + 1 => '121'.
return new Date(
+match[1],
+(match[2] || 1) - 1,
+match[3] || 1,
+match[4] || 0,
+(match[5] || 0) - timeOffset,
+match[6] || 0,
+match[7] || 0
);
// Use local time when no timezone offset specifed.
if (!match[8]) {
// match[n] can only be string or undefined.
// But take care of '12' + 1 => '121'.
return new Date(
+match[1],
+(match[2] || 1) - 1,
+match[3] || 1,
+match[4] || 0,
+(match[5] || 0),
+match[6] || 0,
+match[7] || 0
);
}
// Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,
// https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).
// For example, system timezone is set as "Time Zone: America/Toronto",
// then these code will get different result:
// `new Date(1478411999999).getTimezoneOffset(); // get 240`
// `new Date(1478412000000).getTimezoneOffset(); // get 300`
// So we should not use `new Date`, but use `Date.UTC`.
else {
var hour = +match[4] || 0;
if (match[8].toUpperCase() !== 'Z') {
hour -= match[8].slice(0, 3);
}
return new Date(Date.UTC(
+match[1],
+(match[2] || 1) - 1,
+match[3] || 1,
hour,
+(match[5] || 0),
+match[6] || 0,
+match[7] || 0
));
}
}
else if (value == null) {
return new Date(NaN);
......
......@@ -22,10 +22,10 @@
</style>
<h1>time scale label shoule in local time when timestamp (in UTC) input, tick should align with day.</h1>
<h1>time scale label should in local time when timestamp (in UTC) input, tick should align with day.</h1>
<div class="chart" id="chart0"></div>
<h1>time scale label shoule in UTC time when option.useUTC is `true`, tick should not align with day.</h1>
<h1>time scale label should in UTC time when option.useUTC is `true`, tick should not align with day.</h1>
<div class="chart" id="chart1"></div>
<h1>useUTC: null, should display '00:00 01-03' in tooltip on the 1st point</h1>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册