Skip to content
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

Dependency tz-offset returning wrong value #217

Closed
jplandry908 opened this issue Mar 10, 2020 · 4 comments
Closed

Dependency tz-offset returning wrong value #217

jplandry908 opened this issue Mar 10, 2020 · 4 comments

Comments

@jplandry908
Copy link

i.e. America/New_York is currently returning 300, but should be returning 240. I tried v0.0.1 (the version this package uses) as well as v0.0.2 (the version currently available). Both version returning 300 so all jobs are 1 hour off.

I suggest maybe moving this to moment instead to resolve this.

For example:

var tzOffset = require("tz-offset");
WRONG UTC OFFSET (used in the code today):
console.log(tzOffset.offsetOf("America/New_York"));

var moment = require("moment");
var tz = require("moment-timezone");
CORRECT OFFSET:
console.log(moment().tz("America/New_York").format('Z'));
CORRECT DATE AND TIME:
console.log(moment().tz("America/New_York").format());

@jplandry908
Copy link
Author

FYI - If anyone is experiencing this issue and wants to apply a quick fix without rewriting too much code, I did the following to fix it.

INSTALL:

  • moment
  • moment-timezone

MAKE THE FOLLOWING CHANGES IN 'scheduled-task.js' ...

DECLARE:
var moment = require("moment");
var tz = require("moment-timezone");

CHANGE THIS FUNCTION:
this.task = () => {
var date = new Date();
if(timezone){
//date = tzOffset.timeAt(date, timezone); //COMMENT OR REMOVE THIS LINE
let offset = moment.tz(moment.utc(), timezone).utcOffset(); //ADD THIS LINE
date = new Date(moment(date).add(offset, 'minutes').format()); //ADD THIS LINE
}
this.tick = setTimeout(this.task, 1000 - date.getMilliseconds() + 1);
task.update(date);
};

@itsjustcon
Copy link

I'm experiencing the same issue. All of my tasks are running 1 hour later than expected.

@ecoleman
Copy link

There is a pending pull request to fix offsets: node-cron/tz-offset#11

@merencia
Copy link
Member

New version released, now using moment-timezone.
#248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants