Skip to content

[BUG] Cron expressions ignore schedule.TZ field, always evaluate in UTC #1044

@AaronJny

Description

@AaronJny

Description

CronSchedule has a TZ field (defined in the struct), but computeNextRun()
in pkg/cron/service.go ignores it entirely. All cron expressions are evaluated
in UTC, causing incorrect trigger times for non-UTC users.

Example: a cron expression 0 9 * * * (daily at 9:00) triggers at UTC 9:00 =
CST 17:00 for users in Asia/Shanghai.

Root Cause

computeNextRun() creates the reference time via time.UnixMilli(nowMS), which
is always UTC. The schedule.TZ field is never read or applied before calling
gronx.NextTickAfter().

Proposed Fix

  1. Read schedule.TZ and convert the reference time to the target timezone
    before computing next tick.
  2. Add a configurable default_timezone in tools.cron config for server-wide
    default.
  3. Use 3-tier fallback: schedule.TZ > config default_timezone > "Asia/Shanghai".

Note: The final fallback to "Asia/Shanghai" could be time.Local instead.
Happy to adjust based on maintainer preference.

Environment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions