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

Missing Cron Execution during DST change #881

Open
ishan393 opened this issue Apr 24, 2024 · 1 comment
Open

Missing Cron Execution during DST change #881

ishan393 opened this issue Apr 24, 2024 · 1 comment
Labels
type:bug Bug reports and bug fixes

Comments

@ishan393
Copy link

ishan393 commented Apr 24, 2024

Description

Hi, thanks to author and everyone contributing for making this amazing library possible.

Encountered an issue where the cron jobs aren't triggering during daylight saving change.

For example: TimeZone - Australia/Melbourne 7 Apr 2024 - Daylight savings time ended and clocks turned back 1 hour
Time goes from 2:59 -> 2:00 (See example below)

Expected Behavior

The Cron job should trigger every half an hour (See example below)

Actual Behavior

The Cron job didn't trigger for one hour and missed two executions. Missing cron job executed log two times (See example below)

Steps to Reproduce

const { CronJob } = require("cron");
const fakeTImers = require("@sinonjs/fake-timers");

process.env.TZ = "Australia/Melbourne";

const main = () => {
  const clock = fakeTImers.install({
    now: new Date("2024-04-07T01:00:00.000"),
  });
  const job = new CronJob(
    "*/30 * * * *", // every 30 minutes
    function () {
      console.log(
        "Cron job executed. The current time is: ",
        new Date().toString()
      );
    },
    null,
    true,
    "Australia/Melbourne"
  );

  console.log("current time is: ", new Date().toString());
  console.log("Going to advance time by 30 minutes");
  clock.tick(1000 * 60 * 30);
  console.log("Time after advancing is ", new Date().toString());
  console.log("\n");

  console.log("current time is: ", new Date().toString());
  console.log("Going to advance time by 30 minutes");
  clock.tick(1000 * 60 * 30);
  console.log("Time after advancing is ", new Date().toString());
  console.log("\n");

  console.log("current time is: ", new Date().toString());
  console.log("Going to advance time by 30 minutes");
  clock.tick(1000 * 60 * 30);
  console.log("Time after advancing is ", new Date().toString());
  console.log("\n");

  console.log("current time is: ", new Date().toString());
  console.log("Going to advance time by 30 minutes");
  clock.tick(1000 * 60 * 30);
  console.log("Time after advancing is ", new Date().toString());
  console.log("\n");

  console.log("current time is: ", new Date().toString());
  console.log("Going to advance time by 30 minutes");
  clock.tick(1000 * 60 * 30);
  console.log("Time after advancing is ", new Date().toString());
  console.log("\n");

  console.log("current time is: ", new Date().toString());
  console.log("Going to advance time by 30 minutes");
  clock.tick(1000 * 60 * 30);
  console.log("Time after advancing is ", new Date().toString());
  console.log("\n");

  console.log("current time is: ", new Date().toString());
  console.log("Going to advance time by 30 minutes");
  clock.tick(1000 * 60 * 30);
  console.log("Time after advancing is ", new Date().toString());
  console.log("\n");
};

main();

Output:

current time is:  Sun Apr 07 2024 01:00:00 GMT+1100 (Australian Eastern Daylight Time)
Going to advance time by 30 minutes
Cron job executed. The current time is:  Sun Apr 07 2024 01:30:00 GMT+1100 (Australian Eastern Daylight Time)
Time after advancing is  Sun Apr 07 2024 01:30:00 GMT+1100 (Australian Eastern Daylight Time)


current time is:  Sun Apr 07 2024 01:30:00 GMT+1100 (Australian Eastern Daylight Time)
Going to advance time by 30 minutes
Cron job executed. The current time is:  Sun Apr 07 2024 02:00:00 GMT+1100 (Australian Eastern Daylight Time)
Time after advancing is  Sun Apr 07 2024 02:00:00 GMT+1100 (Australian Eastern Daylight Time)


current time is:  Sun Apr 07 2024 02:00:00 GMT+1100 (Australian Eastern Daylight Time)
Going to advance time by 30 minutes
Cron job executed. The current time is:  Sun Apr 07 2024 02:30:00 GMT+1100 (Australian Eastern Daylight Time)
Time after advancing is  Sun Apr 07 2024 02:30:00 GMT+1100 (Australian Eastern Daylight Time)


current time is:  Sun Apr 07 2024 02:30:00 GMT+1100 (Australian Eastern Daylight Time)
Going to advance time by 30 minutes
Time after advancing is  Sun Apr 07 2024 02:00:00 GMT+1000 (Australian Eastern Standard Time)


current time is:  Sun Apr 07 2024 02:00:00 GMT+1000 (Australian Eastern Standard Time)
Going to advance time by 30 minutes
Time after advancing is  Sun Apr 07 2024 02:30:00 GMT+1000 (Australian Eastern Standard Time)


current time is:  Sun Apr 07 2024 02:30:00 GMT+1000 (Australian Eastern Standard Time)
Going to advance time by 30 minutes
Cron job executed. The current time is:  Sun Apr 07 2024 03:00:00 GMT+1000 (Australian Eastern Standard Time)
Time after advancing is  Sun Apr 07 2024 03:00:00 GMT+1000 (Australian Eastern Standard Time)


current time is:  Sun Apr 07 2024 03:00:00 GMT+1000 (Australian Eastern Standard Time)
Going to advance time by 30 minutes
Cron job executed. The current time is:  Sun Apr 07 2024 03:30:00 GMT+1000 (Australian Eastern Standard Time)
Time after advancing is  Sun Apr 07 2024 03:30:00 GMT+1000 (Australian Eastern Standard Time)


Your Environment

  • cron version: 3.1.7
  • NodeJS version: 14.17.6
  • Operating System and version: Ubuntu 16.04
  • TypeScript version (if applicable):
  • Link to your project (if applicable):

Might be related to: #563 #638

@sheerlox sheerlox added the type:bug Bug reports and bug fixes label May 17, 2024
@sheerlox
Copy link
Collaborator

Hi, thanks for reporting and providing a reproduction means.

I took note of the issue and will try to dedicate some time to it when possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Bug reports and bug fixes
Projects
None yet
Development

No branches or pull requests

2 participants