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 245 forks source link

Changing the day order breaks it #196

Closed rajpa closed 7 years ago

rajpa commented 7 years ago

hi @bunkat

firstly, thanks for a great package! absolutely love it!!

onto the bug..

if the schedule is specified as "at 8:00 pm on sun, mon, tue, wed, sat" it works.

if the schedule is specified as "at 8:00 pm on mon, tue, wed, sat, sun" it breaks!! by which i mean it skips the first few occurrences completely.

Cheers rajpa

bunkat commented 7 years ago

Yeah, in general Later assumes that all of the constraints are pre-sorted. If you do a console.log on the schedule that is created you will see it is just a buch of key value pairs where the values are arrays. Make sure each of the arrays are sorted before you calculate occurrences and you should be all set.

rajpa commented 7 years ago

thanks @bunkat. the problem arises if I do schedule.next(100, start, end) in which case, the "sun" occurences just vanish completely, having come last... hope that clarifies..

cheers/rajpa

bunkat commented 7 years ago

Sun needs to come first since it's the lowest day value in Later. If you sort the constraints after creating the schedule it will work as expected.