Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support different tz in one scheduler #306

Merged
merged 1 commit into from Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion scheduler.go
Expand Up @@ -1138,7 +1138,12 @@ func (s *Scheduler) cron(cronExpression string, withSeconds bool) *Scheduler {
job = s.getCurrentJob()
}

withLocation := fmt.Sprintf("CRON_TZ=%s %s", s.location.String(), cronExpression)
var withLocation string
if strings.HasPrefix(cronExpression, "TZ=") || strings.HasPrefix(cronExpression, "CRON_TZ=") {
withLocation = cronExpression
} else {
withLocation = fmt.Sprintf("CRON_TZ=%s %s", s.location.String(), cronExpression)
}

var (
cronSchedule cron.Schedule
Expand Down
1 change: 1 addition & 0 deletions scheduler_test.go
Expand Up @@ -1673,6 +1673,7 @@ func TestScheduler_Cron(t *testing.T) {
{"every minute in range, monday thru friday", "15-30 * * * 1-5", ft.onNow(time.UTC).Add(15 * time.Minute), nil},
{"at every minute past every hour from 1 through 5 on every day-of-week from Monday through Friday.", "* 1-5 * * 1-5", ft.onNow(time.UTC).Add(13 * time.Hour), nil},
{"hourly", "@hourly", ft.onNow(time.UTC).Add(1 * time.Hour), nil},
{"every day 1am in shanghai", "CRON_TZ=Asia/Shanghai 0 1 * * *", ft.onNow(time.UTC).Add(5 * time.Hour), nil},
{"bad expression", "bad", time.Time{}, wrapOrError(fmt.Errorf("expected exactly 5 fields, found 1: [bad]"), ErrCronParseFailure)},
}

Expand Down