Search code examples
javascriptmomentjslaterjs

Later.js wrong response from next()


I'm using later.js to calculate the next occurrence of a cron, and it returns wrong result.

Here's my code:

var laterCron = later.parse.cron("5 11,15,19,23,3,7 * * *");
console.log(later.schedule(laterCron).next());

The response is

Fri Dec 06 2013 13:05:00 GMT+0200 (EET)

(Now is Thu Dec 05 2013 14:36:38 GMT+0200 (EET)) But the next run should be at 15:05 GMT (or 17:05 GMT+02)

Any help? (I use the newest version, 1.1.6)

Fiddle:

var laterCron = later.parse.cron("5 11,15,19,23,3,7 * * *");
console.log(later.schedule(laterCron).next());
console.log("Thu Dec 05 2013 9:05:00 GMT+0200", later.schedule(laterCron).isValid(new Date("Thu Dec 05 2013 9:05:00 GMT+0200")));
console.log("Thu Dec 05 2013 13:05:00 GMT+0200", later.schedule(laterCron).isValid(new Date("Thu Dec 05 2013 13:05:00 GMT+0200")));
console.log("Thu Dec 05 2013 17:05:00 GMT+0200", later.schedule(laterCron).isValid(new Date("Thu Dec 05 2013 17:05:00 GMT+0200")));
console.log("Thu Dec 05 2013 21:05:00 GMT+0200", later.schedule(laterCron).isValid(new Date("Thu Dec 05 2013 21:05:00 GMT+0200")));
console.log("Fri Dec 06 2013 01:05:00 GMT+0200", later.schedule(laterCron).isValid(new Date("Fri Dec 06 2013 01:05:00 GMT+0200")));
console.log("Fri Dec 06 2013 05:05:00 GMT+0200", later.schedule(laterCron).isValid(new Date("Fri Dec 06 2013 05:05:00 GMT+0200")));
console.log("Fri Dec 06 2013 09:05:00 GMT+0200", later.schedule(laterCron).isValid(new Date("Fri Dec 06 2013 09:05:00 GMT+0200")));
console.log("Fri Dec 06 2013 13:05:00 GMT+0200", later.schedule(laterCron).isValid(new Date("Fri Dec 06 2013 13:05:00 GMT+0200")));
console.log("Fri Dec 06 2013 17:05:00 GMT+0200", later.schedule(laterCron).isValid(new Date("Fri Dec 06 2013 17:05:00 GMT+0200")));
console.log("Fri Dec 06 2013 21:05:00 GMT+0200", later.schedule(laterCron).isValid(new Date("Fri Dec 06 2013 21:05:00 GMT+0200")));

This is the output:

Date {Fri Dec 06 2013 12:05:00 GMT+0100 (Romance Standard Time)}
Thu Dec 05 2013 9:05:00 GMT+0200 true
Thu Dec 05 2013 13:05:00 GMT+0200 true
Thu Dec 05 2013 17:05:00 GMT+0200 false
Thu Dec 05 2013 21:05:00 GMT+0200 false
Fri Dec 06 2013 01:05:00 GMT+0200 false
Fri Dec 06 2013 05:05:00 GMT+0200 true
Fri Dec 06 2013 09:05:00 GMT+0200 true
Fri Dec 06 2013 13:05:00 GMT+0200 true
Fri Dec 06 2013 17:05:00 GMT+0200 false
Fri Dec 06 2013 21:05:00 GMT+0200 false

Solution

  • Sorting the hours (3,7,11,15,19,23) seems to solve the issue..