diff --git a/lib/timeline/TimeStep.js b/lib/timeline/TimeStep.js index 13b91b855..7ea531c2c 100644 --- a/lib/timeline/TimeStep.js +++ b/lib/timeline/TimeStep.js @@ -222,7 +222,23 @@ TimeStep.prototype.next = function() { break; case 'weekday': // intentional fall through case 'day': this.current.add(this.step, 'day'); break; - case 'week': this.current.add(this.step, 'week'); break; + case 'week': + if (this.current.weekday() !== 0){ // we had a month break not correlating with a week's start before + this.current.weekday(0); // switch back to week cycles + this.current.add(this.step, 'week'); + } else if(this.options.showMajorLabels === false) { + this.current.add(this.step, 'week'); // the default case + } else { // first day of the week + var nextWeek = this.current.clone(); + nextWeek.add(1, 'week'); + if(nextWeek.isSame(this.current, 'month')){ // is the first day of the next week in the same month? + this.current.add(this.step, 'week'); // the default case + } else { // inject a step at each first day of the month + this.current.add(this.step, 'week'); + this.current.date(1); + } + } + break; case 'month': this.current.add(this.step, 'month'); break; case 'year': this.current.add(this.step, 'year'); break; default: break; @@ -532,7 +548,7 @@ TimeStep.prototype.isMajor = function() { case 'day': return (date.date() == 1); case 'week': - return (Math.ceil(date.date() / 7) == 1); // is 1st week in the month? + return (date.date() == 1); case 'month': return (date.month() == 0); case 'year':