fix(cron): apply timezone from schedule.TZ for cron expressions
CronSchedule has a TZ field but computeNextRun() ignores it, using time.UnixMilli() which returns UTC. This causes cron expressions like '0 9 * * *' (daily at 9am) to trigger at UTC 9:00 = CST 17:00. Now loads schedule.TZ (defaulting to Asia/Shanghai when empty) and converts the reference time to the target timezone before computing the next tick with gronx.
This commit is contained in:
parent
6f5930624b
commit
150bb34e51
1 changed files with 8 additions and 0 deletions
|
|
@ -266,6 +266,14 @@ func (cs *CronService) computeNextRun(schedule *CronSchedule, nowMS int64) *int6
|
||||||
|
|
||||||
// Use gronx to calculate next run time
|
// Use gronx to calculate next run time
|
||||||
now := time.UnixMilli(nowMS)
|
now := time.UnixMilli(nowMS)
|
||||||
|
// Apply timezone if specified, default to Asia/Shanghai
|
||||||
|
tz := schedule.TZ
|
||||||
|
if tz == "" {
|
||||||
|
tz = "Asia/Shanghai"
|
||||||
|
}
|
||||||
|
if loc, err := time.LoadLocation(tz); err == nil {
|
||||||
|
now = now.In(loc)
|
||||||
|
}
|
||||||
nextTime, err := gronx.NextTickAfter(schedule.Expr, now, false)
|
nextTime, err := gronx.NextTickAfter(schedule.Expr, now, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[cron] failed to compute next run for expr '%s': %v", schedule.Expr, err)
|
log.Printf("[cron] failed to compute next run for expr '%s': %v", schedule.Expr, err)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue