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
- Read
schedule.TZ and convert the reference time to the target timezone
before computing next tick.
- Add a configurable
default_timezone in tools.cron config for server-wide
default.
- 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
Description
CronSchedulehas aTZfield (defined in the struct), butcomputeNextRun()in
pkg/cron/service.goignores it entirely. All cron expressions are evaluatedin 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 viatime.UnixMilli(nowMS), whichis always UTC. The
schedule.TZfield is never read or applied before callinggronx.NextTickAfter().Proposed Fix
schedule.TZand convert the reference time to the target timezonebefore computing next tick.
default_timezoneintools.cronconfig for server-widedefault.
schedule.TZ> configdefault_timezone>"Asia/Shanghai".Environment