bunkat / later

A javascript library for defining recurring schedules and calculating future (or past) occurrences for them. Includes support for using English phrases and Cron schedules. Works in Node and in the browser.
http://bunkat.github.io/later/
MIT License
2.42k stars 244 forks source link

Bug getting next() occurrences with composite schedule where each clause has a year #216

Open tscizzle opened 7 years ago

tscizzle commented 7 years ago

It seems one can't use and() if every clause has a year(). The schedule can be created correctly (I see an array like [{M: [2], Y: [2017]}, {M: [4], Y: [2018]}] in the schedules field), but calling next() errors. So it appears the issue is in getting occurrences for composite schedules, not in the parser.

e.g. it errors on later.schedule(sched).next(2) when sched is

.on(2).month().on(2017).year()
.and()
.on(3).month().on(2018).year()
.and()
.on(4).month().on(2019).year()

but not when sched is

.on(2).month()
.and()
.on(3).month().on(2018).year()
.and()
.on(4).month().on(2019).year()

Note that the second one's first clause is .on(2).month(), WITHOUT .on(2017).year().

As another clue, re-ordering the clauses (for example having the clause without .year() be the third clause instead of first) changes the behavior, in that case causing it to error.

Been liking the package! But this does appear to be a bug.