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

recur() function not working correctly? #176

Open telmof opened 8 years ago

telmof commented 8 years ago

I'm using Later.js for recurring events. I'm trying to test the recur() function and it doesn't seem to be working properly, and I don't know why. Here's my example:

var schedule_hourly = later.schedule(later.parse.recur().every(x).hour()),
    start_hourly = moment(start_day + " " + start_time, 'YYYY/MM/DD HH:mm');
var occurrences_hourly = schedule_hourly.next(y, start_hourly);

for (var i = 0; i < occurrences_hourly.length; i++) {
    var execution_dates_hourly = [];
    execution_dates_hourly = moment(occurrences_hourly[i]).format('YYYY/MM/DD HH:mm');
    console.log(execution_dates_hourly);
}

Where:

With an initial date of 2016/07/20 10:00, x=2 and y=5 I get the following on the console:

2016/07/20 10:00
2016/07/20 12:00
2016/07/20 14:00
2016/07/20 16:00
2016/07/20 18:00

So it's working correctly. I get a repeating event every 2 hours, starting at 10:00 hours that repeats 5 times.

However, if I change the x to 8, I get this:

2016/07/20 16:00
2016/07/21 00:00
2016/07/21 08:00
2016/07/21 16:00
2016/07/22 00:00

Why does it start at 16:00 now? Shouldn't it start at 10:00 like before and go to 18:00 next?