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

Incorrect date #199

Open alesmenzelsocialbakers opened 7 years ago

alesmenzelsocialbakers commented 7 years ago

later.schedule(...).next(...) gives incorrect next date

Reproduce steps:

var interval = later.parse.text('every 1 mins')
later.schedule(interval).next(1)

Current datetime = Wed Feb 15 2017 11:18:16 GMT+0100 (Central Europe Standard Time) Result: Wed Feb 15 2017 11:18:16 GMT+0100 (Central Europe Standard Time) Expected result: Wed Feb 15 2017 11:19:00 GMT+0100 (Central Europe Standard Time)

bunkat commented 7 years ago

The start time is considered valid if it meets all of the constraints specified. Since you've only specified that every minute is valid, the current time meets that constraint and is returned. To get your expected result you can either add another constraint for 0 seconds or modify the start time to be on the next minute.

alesmenzelsocialbakers commented 7 years ago

That does not help. Trying every 0 seconds every 1 minute which results in running 60 times per minute - not what i wanted.

I want to specify interval to run every minute from the closest minute (i.e. first comment).

alesmenzelsocialbakers commented 7 years ago

BTW: If I set the interval to 59s, it returns this:

See the +1s and +59s differences, that cant be right.

[ 2017-02-15T18:45:59.078Z,
  2017-02-15T18:46:00.078Z,
  2017-02-15T18:46:59.078Z,
  2017-02-15T18:47:00.078Z,
  2017-02-15T18:47:59.078Z ]

Secondly: Interval 'every 60 s' returns error code 6.

Repro steps:

const later = require('later');
const interval = later.parse.text('every 60 s');
const res = later.schedule(interval).next(5);
console.log(res);
mitar commented 7 years ago

Try using this workaround.