Skip to content

Using set interval for running on a date ( run once ) calls the callback twice #39

@danAlmogSB

Description

@danAlmogSB

Describe the bug

Node.js version: v24.11.1

OS version: macOs

Description: Using set interval for running on a date ( run once ) calls the callback twice

Actual behavior

callback called 2 times

Expected behavior

callback should be called once

Code to reproduce

`const later = require("@breejs/later");
const trackedJobs = [];
let count = 1;
const originalDate = new Date();
const newDate = new Date(originalDate.setSeconds(originalDate.getSeconds() + 60));
const job = {
"runDate": newDate,
"cronTimezone": "Europe/Athens",
};
console.log(originalDate);
function getScheduleFromJob(job) {
const dateWithZone = new Date(new Date(job.runDate).toLocaleString('en', { timeZone: job.cronTimezone }));
return later.parse.recur().on(dateWithZone).fullDate();
}

function runJob(job) {
console.log(count++);
console.log(new Date());
console.log(job);
}

const schedule = getScheduleFromJob(job);
// eslint-disable-next-line no-param-reassign
job.interval = later.setInterval(() => runJob(job), schedule, job.cronTimezone);`

prints:
`2025-11-19T12:20:26.768Z
1
2025-11-19T12:20:26.787Z
{
runDate: 2025-11-19T12:20:26.768Z,
cronTimezone: 'Europe/Athens',
interval: { isDone: [Function: isDone], clear: [Function: clear] }
}
2
2025-11-19T12:20:27.794Z
{
runDate: 2025-11-19T12:20:26.768Z,
cronTimezone: 'Europe/Athens',
interval: { isDone: [Function: isDone], clear: [Function: clear] }
}

Process finished with exit code 0`

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions