fix(cron): apply timezone to all schedule kinds, not just cron

Move TZ application before schedule kind switch in MergeCronSchedule.
Ensure timezone applies consistently to cron, every, and at expressions.
This commit is contained in:
viettranx committed 2026-04-02 08:23:05 +07:00
1 parent 7d5c670708
commit c48639369b
1 file changed
+9 -10
+9 -10
View File
@@ -237,6 +237,8 @@ func MergeCronSchedule(current CronSchedule, patch *CronSchedule) CronSchedule {
}
merged := CronSchedule{Kind: newKind}
// TZ: always use patch value for all schedule kinds. Empty = UTC (default).
merged.TZ = patch.TZ
switch newKind {
case "cron":
if patch.Expr != "" {
@@ -244,9 +246,6 @@ func MergeCronSchedule(current CronSchedule, patch *CronSchedule) CronSchedule {
} else if current.Kind == newKind {
merged.Expr = current.Expr
}
// TZ: always use patch value. Empty = UTC (default).
// Callers (UI, agent tool) send full schedule via spread, so empty is explicit.
merged.TZ = patch.TZ
case "every":
if patch.EveryMS != nil {
merged.EveryMS = patch.EveryMS
@@ -298,25 +297,25 @@ func ValidateCronSchedule(schedule *CronSchedule) error {
func ApplyCronScheduleUpdates(updates map[string]any, schedule CronSchedule) {
updates["schedule_kind"] = schedule.Kind
// TZ applies to all schedule kinds (used for display and cron evaluation).
if schedule.TZ != "" {
updates["timezone"] = schedule.TZ
} else {
updates["timezone"] = nil
}
switch schedule.Kind {
case "cron":
updates["cron_expression"] = schedule.Expr
if schedule.TZ != "" {
updates["timezone"] = schedule.TZ
} else {
updates["timezone"] = nil
}
updates["interval_ms"] = nil
updates["run_at"] = nil
case "every":
updates["cron_expression"] = nil
updates["timezone"] = nil
updates["interval_ms"] = *schedule.EveryMS
updates["run_at"] = nil
case "at":
runAt := time.UnixMilli(*schedule.AtMS)
updates["cron_expression"] = nil
updates["timezone"] = nil
updates["interval_ms"] = nil
updates["run_at"] = runAt
}