diff --git a/lib/timeline/TimeStep.js b/lib/timeline/TimeStep.js index dc3991ed..12a7336c 100644 --- a/lib/timeline/TimeStep.js +++ b/lib/timeline/TimeStep.js @@ -216,7 +216,17 @@ TimeStep.prototype.next = function() { 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'); break; + case 'hour': + this.current.add(this.moment.duration(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.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; @@ -228,10 +238,10 @@ TimeStep.prototype.next = function() { if (this.step != 1) { // round down to the correct major value switch (this.scale) { - case 'millisecond': if(this.current.milliseconds() < this.step) this.current.milliseconds(0); break; - case 'second': if(this.current.seconds() < this.step) this.current.seconds(0); break; - case 'minute': if(this.current.minutes() < this.step) this.current.minutes(0); break; - case 'hour': if(this.current.hours() < this.step) this.current.hours(0); break; + case 'millisecond': if(this.current.milliseconds() > 0 && this.current.milliseconds() < this.step) this.current.milliseconds(0); break; + case 'second': if(this.current.seconds() > 0 && this.current.seconds() < this.step) this.current.seconds(0); break; + case 'minute': if(this.current.minutes() > 0 && this.current.minutes() < this.step) this.current.minutes(0); break; + case 'hour': if(this.current.hours() > 0 && this.current.hours() < this.step) this.current.hours(0); break; case 'weekday': // intentional fall through case 'day': if(this.current.date() < this.step+1) this.current.date(1); break; case 'month': if(this.current.month() < this.step) this.current.month(0); break;