Git Product home page Git Product logo

Comments (10)

santigimeno avatar santigimeno commented on May 18, 2024

It looks again a DST transition issue. Will look into it when time permits

from cron-parser.

santigimeno avatar santigimeno commented on May 18, 2024

Thanks for the report

from cron-parser.

JohnyDays avatar JohnyDays commented on May 18, 2024

Can i somehow disable timezone handling? I don't need it for this particular case
EDIT: Might also be relevant, my timezone is Lisbon (GMT+1 currently because of DST)

from cron-parser.

santigimeno avatar santigimeno commented on May 18, 2024

I would use the latest 1.x.x version.

from cron-parser.

JohnyDays avatar JohnyDays commented on May 18, 2024

That seems to work perfectly, thanks! If you need some more information when debugging the issue just hit me up! 👍

from cron-parser.

harrisiirak avatar harrisiirak commented on May 18, 2024

@santigimeno @JohnyDays a good catch. Let me know how this is going. Thanks for the reporting @JohnyDays!

from cron-parser.

santigimeno avatar santigimeno commented on May 18, 2024

I've been looking a little into this. Changing your code to use moment with timezone information should do it:

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());
}

from cron-parser.

santigimeno avatar santigimeno commented on May 18, 2024

For the issue itself, I have reduced the case to this. It's due to how moment.startOf() behaves. I don't know if it's a bug or 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'));
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:

Sun Oct 30 2016 02:00:00 GMT+0200 <-- Just 1 hour before the DST end @ Europe/Madrid
Sun Oct 30 2016 02:00:00 GMT+0100 <-- DST end transition @ Europe/Madrid works correctly
Sun Oct 30 2016 02:00:00 GMT+0200 <-- Smthing wrong?? It goes back to the previous hour

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

Sun Oct 30 2016 02:00:00 GMT+0200 <-- Just 1 hour before the DST end @ Europe/Madrid
Sun Oct 30 2016 02:00:00 GMT+0100 <-- DST end transition @ Europe/Madrid works correctly
Sun Oct 30 2016 02:00:00 GMT+0100 <-- Everything correct. It remains in the same hour

Thoughts? /cc @harrisiirak @mj1856

from cron-parser.

santigimeno avatar santigimeno commented on May 18, 2024

It looks like this issue: moment/moment#2749

from cron-parser.

santigimeno avatar santigimeno commented on May 18, 2024

Tentative fix #73. /cc @harrisiirak @JohnyDays

from cron-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.