New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stuck in while loop indefinitely #72
Comments
It looks again a DST transition issue. Will look into it when time permits |
Thanks for the report |
Can i somehow disable timezone handling? I don't need it for this particular case |
I would use the latest |
That seems to work perfectly, thanks! If you need some more information when debugging the issue just hit me up! 👍 |
@santigimeno @JohnyDays a good catch. Let me know how this is going. Thanks for the reporting @JohnyDays! |
I've been looking a little into this. Changing your code to use var expression = "0 12 * * *"
var cron = require("cron-parser")
var moment = require('moment-timezone');
var currentDate = moment().tz('Europe/Lisbon');
var iterator = cron.parseExpression(expression, {currentDate:currentDate})
for (var i=0; i<40;i++) {
console.log(iterator.next().toString());
} |
For the issue itself, I have reduced the case to this. It's due to how 'use strict';
const moment = require('moment-timezone');
var m = moment(new Date('Sun Oct 30 2016 02:00:00 GMT+0200'));
console.log(m.toString(), '<-- Just 1 hour before the DST end @ Europe/Madrid');
m.add(1, 'hours');
console.log(m.toString(), '<-- DST end transition @ Europe/Madrid works correctly');
m.startOf('hour');
console.log(m.toString(), '<-- Smthing wrong?? It goes back to the previous hour'); It's output being:
OTOH, if the timezone is explicitly used, it works as expected 'use strict';
const moment = require('moment-timezone');
var m = moment(new Date('Sun Oct 30 2016 02:00:00 GMT+0200')).tz('Europe/Madrid');
console.log(m.toString(), '<-- Just 1 hour before the DST end @ Europe/Madrid');
m.add(1, 'hours');
console.log(m.toString(), '<-- DST end transition @ Europe/Madrid works correctly');
m.startOf('hour');
console.log(m.toString(), '<-- Everything correct. It remains in the same hour'); It's output being
Thoughts? /cc @harrisiirak @mj1856 |
It looks like this issue: moment/moment#2749 |
On DST end transition, setting the date to the `startOf` `hour`, `minute` or `second` after having added 1 `hour`, `minute` or `second` to the date, would result in the date set to the initial value causing an infinite loop. Example: ```js 'use strict'; const moment = require('moment-timezone'); var m = moment(new Date('Sun Oct 30 2016 02:00:00 GMT+0200')); console.log(m.toString(), '<-- Just 1 hour before the DST end @ Europe/Madrid'); m.add(1, 'hours'); console.log(m.toString(), '<-- DST end transition @ Europe/Madrid works correctly'); m.startOf('hour'); console.log(m.toString(), '<-- Smthing wrong?? It goes back to the previous hour'); ``` Fixes: harrisiirak#72
On DST end transition, setting the date to the `startOf` `hour`, `minute` or `second` after having added 1 `hour`, `minute` or `second` to the date, would result in the date set to the initial value causing an infinite loop. Example: ```js 'use strict'; const moment = require('moment-timezone'); var m = moment(new Date('Sun Oct 30 2016 02:00:00 GMT+0200')); console.log(m.toString(), '<-- Just 1 hour before the DST end @ Europe/Madrid'); m.add(1, 'hours'); console.log(m.toString(), '<-- DST end transition @ Europe/Madrid works correctly'); m.startOf('hour'); console.log(m.toString(), '<-- Smthing wrong?? It goes back to the previous hour'); ``` Fixes: harrisiirak#72
On DST end transition, setting the date to the `startOf` `hour`, `minute` or `second` after having added 1 `hour`, `minute` or `second` to the date, would result in the date set to the initial value causing an infinite loop. Example: ```js 'use strict'; const moment = require('moment-timezone'); var m = moment(new Date('Sun Oct 30 2016 02:00:00 GMT+0200')); console.log(m.toString(), '<-- Just 1 hour before the DST end @ Europe/Madrid'); m.add(1, 'hours'); console.log(m.toString(), '<-- DST end transition @ Europe/Madrid works correctly'); m.startOf('hour'); console.log(m.toString(), '<-- Smthing wrong?? It goes back to the previous hour'); ``` Fixes: harrisiirak#72 Ref: moment/moment#2749
Tentative fix #73. /cc @harrisiirak @JohnyDays |
On DST end transition, setting the date to the `startOf` `hour`, `minute` or `second` after having added 1 `hour`, `minute` or `second` to the date, would result in the date set to the initial value causing an infinite loop. Example: ```js 'use strict'; const moment = require('moment-timezone'); var m = moment(new Date('Sun Oct 30 2016 02:00:00 GMT+0200')); console.log(m.toString(), '<-- Just 1 hour before the DST end @ Europe/Madrid'); m.add(1, 'hours'); console.log(m.toString(), '<-- DST end transition @ Europe/Madrid works correctly'); m.startOf('hour'); console.log(m.toString(), '<-- Smthing wrong?? It goes back to the previous hour'); ``` Fixes: harrisiirak#72 Ref: moment/moment#2749
On DST end transition, setting the date to the `startOf` `hour`, `minute` or `second` after having added 1 `hour`, `minute` or `second` to the date, would result in the date set to the initial value causing an infinite loop. Example: ```js 'use strict'; const moment = require('moment-timezone'); var m = moment(new Date('Sun Oct 30 2016 02:00:00 GMT+0200')); console.log(m.toString(), '<-- Just 1 hour before the DST end @ Europe/Madrid'); m.add(1, 'hours'); console.log(m.toString(), '<-- DST end transition @ Europe/Madrid works correctly'); m.startOf('hour'); console.log(m.toString(), '<-- Smthing wrong?? It goes back to the previous hour'); ``` Fixes: harrisiirak#72 Ref: moment/moment#2749
I found a minimal repro case, it always gets stuck in the 27th cycle (script never ends)
I have also tried to recreate the parser on every iteration of the loop, but the results were the same.
Any idea what it might be?
Thanks
The text was updated successfully, but these errors were encountered: