From 3a10511c37404e3e6e5babd1fb242827630d3a74 Mon Sep 17 00:00:00 2001 From: Reed Date: Fri, 17 Feb 2017 02:15:42 -0500 Subject: [PATCH] fixes timestep next issue (#2732) --- lib/timeline/TimeStep.js | 52 +++++++++++++--------------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/lib/timeline/TimeStep.js b/lib/timeline/TimeStep.js index 4bb8f3dd..2ea1a4fa 100644 --- a/lib/timeline/TimeStep.js +++ b/lib/timeline/TimeStep.js @@ -193,46 +193,26 @@ TimeStep.prototype.next = function() { // Two cases, needed to prevent issues with switching daylight savings // (end of March and end of October) - if (this.current.month() < 6) { - switch (this.scale) { - case 'millisecond': this.current.add(this.step, 'millisecond'); break; - case 'second': this.current.add(this.step, 'second'); break; - case 'minute': this.current.add(this.step, 'minute'); break; - case 'hour': - this.current.add(this.step, 'hour'); - // in case of skipping an hour for daylight savings, adjust the hour again (else you get: 0h 5h 9h ... instead of 0h 4h 8h ...) - // TODO: is this still needed now we use the function of moment.js? - this.current.subtract(this.current.hours() % this.step, 'hour'); - break; - case 'weekday': // intentional fall through - case 'day': this.current.add(this.step, 'day'); break; - case 'month': this.current.add(this.step, 'month'); break; - case 'year': this.current.add(this.step, 'year'); break; - default: break; - } - } - else { - switch (this.scale) { - case 'millisecond': this.current.add(this.step, 'millisecond'); break; - case 'second': this.current.add(this.step, 'second'); break; - case 'minute': this.current.add(this.step, 'minute'); break; - case 'hour': - this.current.add(this.moment.duration(this.step, 'hour')); + switch (this.scale) { + case 'millisecond': this.current.add(this.step, 'millisecond'); break; + case 'second': this.current.add(this.step, 'second'); break; + case 'minute': this.current.add(this.step, 'minute'); break; + case 'hour': + this.current.add(this.step, 'hour'); - // correct for daylight saving - // FIXME: use this.current.add(moment.duration(this.step, 'hour')) - // see http://momentjs.com/docs/#special-considerations-for-months-and-years + if (this.current.month() < 6) { + this.current.subtract(this.current.hours() % this.step, 'hour'); + } else { if (this.current.hours() % this.step !== 0) { this.current.add(this.step - this.current.hours() % this.step, 'hour'); } - - break; - case 'weekday': // intentional fall through - case 'day': this.current.add(this.step, 'day'); break; - case 'month': this.current.add(this.step, 'month'); break; - case 'year': this.current.add(this.step, 'year'); break; - default: break; - } + } + break; + case 'weekday': // intentional fall through + case 'day': this.current.add(this.step, 'day'); break; + case 'month': this.current.add(this.step, 'month'); break; + case 'year': this.current.add(this.step, 'year'); break; + default: break; } if (this.step != 1) {