From 878829b46c4273b8a6793685b83bcecdb5313f8e Mon Sep 17 00:00:00 2001 From: 100pah Date: Mon, 20 Apr 2020 16:59:30 -0400 Subject: [PATCH] fix: calendar timezone bug in DST. Fix #12172. And add test cases. --- src/coord/calendar/Calendar.js | 19 ++-- test/calendar-timezone.html | 173 +++++++++++++++++++++++++++++++++ 2 files changed, 186 insertions(+), 6 deletions(-) create mode 100644 test/calendar-timezone.html diff --git a/src/coord/calendar/Calendar.js b/src/coord/calendar/Calendar.js index e397c0ba6c..cf77e70f10 100644 --- a/src/coord/calendar/Calendar.js +++ b/src/coord/calendar/Calendar.js @@ -372,10 +372,13 @@ Calendar.prototype = { range.reverse(); } - var allDay = - Math.round((range[1].time - range[0].time) / PROXIMATE_ONE_DAY) + 1; + var allDay = Math.floor(range[1].time / PROXIMATE_ONE_DAY) + - Math.floor(range[0].time / PROXIMATE_ONE_DAY) + 1; - // Consider case: + // Consider case1 (#11677 #10430): + // Set the system timezone as "UK", set the range to `['2016-07-01', '2016-12-31']` + + // Consider case2: // Firstly set system timezone as "Time Zone: America/Toronto", // ``` // var first = new Date(1478412000000 - 3600 * 1000 * 2.5); @@ -388,11 +391,15 @@ Calendar.prototype = { var endDateNum = range[1].date.getDate(); date.setDate(startDateNum + allDay - 1); // The bias can not over a month, so just compare date. - if (date.getDate() !== endDateNum) { + var dateNum = date.getDate(); + if (dateNum !== endDateNum) { var sign = date.getTime() - range[1].time > 0 ? 1 : -1; - while (date.getDate() !== endDateNum && (date.getTime() - range[1].time) * sign > 0) { + while ( + (dateNum = date.getDate()) !== endDateNum + && (date.getTime() - range[1].time) * sign > 0 + ) { allDay -= sign; - date.setDate(startDateNum + allDay - 1); + date.setDate(dateNum - sign); } } diff --git a/test/calendar-timezone.html b/test/calendar-timezone.html new file mode 100644 index 0000000000..ede1b35b65 --- /dev/null +++ b/test/calendar-timezone.html @@ -0,0 +1,173 @@ + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +