Skip to content

Feature Request: Timezone Support for Deno.cron #21562

@Hexagon

Description

@Hexagon

Today, Deno.cron schedules tasks based on the local time of the server. This can be limiting for applications that operate across multiple time zones. I propose adding timezone support to Deno.cron to address this.

Solution:

Introduce an optional timezone parameter in the Deno.cron function. This would allow developers to specify the timezone in which the cron pattern should be interpreted. This would increase the flexibility and usability of Deno.cron for developers managing international projects and/or website backends. It would also avoid the complexity of converting cron patterns to different time zones manually.

Example:

Deno.cron("cron1", "0 0 9 * * *", () => {
    console.log("This function will run every day at 9:00 AM UTC.");
});

Deno.cron("cron2", "0 0 9 * * *", () => {
    console.log("This function will run every day at 9:00 AM Eastern Time.");
}, { timezone: "America/New_York" });

Current Limitations with saffron:

Currently, Deno.cron relies on the saffron crate for parsing cron patterns, which does not support timezones. This limitation means that all cron jobs are inherently tied to the local timezone of the server. To overcome this, I've created a new crate called croner which includes timezone support by accepting a DateTime<Tz>, it also contains additional benefits such as optional second granularity, and (opt-out) POSIX compliant pattern.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ext/cronsuggestionsuggestions for new features (yet to be agreed)
    No fields configured for suggestion.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions