breejs / later

*Maintained fork of Later.* A javascript library for defining recurring schedules and calculating future (or past) occurrences for them. Includes support for using English phrases and Cron schedules. Works in Node and in the browser.
https://breejs.github.io/later/
MIT License
136 stars 13 forks source link

Running twice within a second when second is fixed #13

Closed aateek-albanero closed 1 year ago

aateek-albanero commented 3 years ago

I am trying to trigger a job once at a specific moment - 2021-06-14T18:14:00.000Z. But the job is being triggered twice. The code is given below:

const later = require('@breejs/later');

const schedule = {
  schedules: [
    {
      year: [2021],
      month: [6],
      day: [14],
      hour: [18],
      minute: [14],
      second: [0],
    },
  ],
};

later.setInterval(() => {
  console.log(`[${new Date().toISOString()}] Job triggered`);
}, schedule);

Output of the above code:

[2021-06-14T18:14:00.681Z] Job triggered
[2021-06-14T18:14:01.702Z] Job triggered

Why is the job being triggered twice? Also, if I don't specify second then job is triggered every second in 14th minute of the mentioned date and time. Is this the expected behaviour? Could anyone please help?

I don't want to use setTimeout as I want to keep the schedule generic.

shadowgate15 commented 1 year ago

This is an invalid schedule. Schedules are defined with s, m, etc. See documentation.