Closed mitar closed 7 years ago
Possible workaround:
later.schedule(later.parse.text('every 4 hours')).next(2, later.schedule(later.parse.text('every 4 hours')).prev(1, time))[1]
Mon Feb 20 2017 04:00:00 GMT-0800 (PST)
So it seems it returns current time if second argument is between noon and 1 AM, and if it is after 1 AM, then it return 4 AM as next time.
It seems this is a known workaround.
I will open a pull request to use this workaround here.
Hmmm, this is not what I see with the sample app at https://jcplayground.meteorapp.com/
Nevermind the above, I see now what you are saying (now that it is after noon local time, the above runs immediately and presumably will for the next hour...)
Just merged your PR on this.
Currently, in documentation, it is written:
I understand this that if I have a schedule that job should run every 4 hours (midnight, 4 AM, 8 AM and so on), and I call if without after or delay, the first time it will run will be at some of those 4 hours times.
This is not what happens. The first time is run almost immediately, and then the rerun is done at 4 AM, 8 AM and so on.
I think the reason is that scheduling more or less gets converted to this call:
The reason for that is because
doc.after
is set to defaultnew Date(0)
, sodoc.after
gets set tonew Date()
before callingnext(1, doc.after)
. And now the strange thing. It seems if the second argument is in the past, thennext
simply returns the current time, and if it is in the future, then it returns the correct time in the future.Examples from my web console in the browser: