kelektiv / node-cron

Cron for NodeJS.
MIT License
8.33k stars 617 forks source link

unable to use utcOffset #568

Closed arnitkun closed 10 months ago

arnitkun commented 3 years ago

I have a job

someJob = new CronJob( '0 ${minutes} ${hours} * * ${targetday}', async () => { // job stuff }, null, null, null, null, null, '5:30', null, );

i also start the job.

I have also tried giving the constructor an object with key-value pairs; cronTime, onTick ...etc etc.

But the utcOffset does not work and I am unable to figure out why. If i use the same job in a scenario that does not require me to use offset, it works fine.

I am unable to find this in ANY code example except in a couple of git issues and even those do not work for me. have tried giving numbers and string as offset.

Can someone show me a practical example? i have spent hours trying to make it work. also getting no errors.

arnitkun commented 3 years ago

I ended up writing my own function to calculate time with offsets.

dummy-account-practise commented 2 years ago

I ended up writing my own function to calculate time with offsets.

Hi! I'm facing the same issue. Will you please help me out how you've resolved it?

Thanks in advance :)

intcreator commented 1 year ago

FYI this is addressed in #652

AbhimanyuG commented 1 year ago

The issue still exists. Even though I set the offset as 330 (5 hr 30 min ahead of UTC) Input offset:

 { offset: 330 }

From modified time.js

 if (typeof this.utcOffset !== 'undefined') {
    ... skipped ...
console.log({utcZone})
date = date.setZone(utcZone);

Output:

{ utcZone: 'UTC+5' }

This is just some debugging info from my console. The UTC string should've been 'UTC+5:30'

AbhimanyuG commented 1 year ago

Potential fix: https://github.com/AbhimanyuG/node-cron/commit/3364420492f707cc3e5fc217d4cf87640ed283c2

intcreator commented 1 year ago

@AbhimanyuG thanks for the PR! I left a comment for you there 🙂