feat: expose default cron implementation

This commit is contained in:
John Roesler 2025-12-10 13:51:11 -06:00
parent f4c6d141a9
commit e7114cf3a2
No known key found for this signature in database
GPG Key ID: 3AA260B9FCA0A6E1
2 changed files with 17 additions and 0 deletions

View File

@ -348,6 +348,14 @@ func ExampleMonthlyJob() {
)
}
func ExampleNewDefaultCron() {
c := gocron.NewDefaultCron(true)
err := c.IsValid("* * * * * *", time.Local, time.Now())
if err != nil {
panic(err)
}
}
func ExampleNewScheduler() {
s, _ := gocron.NewScheduler()
defer func() { _ = s.Shutdown() }()

9
job.go
View File

@ -140,6 +140,15 @@ func newDefaultCronImplementation(withSeconds bool) Cron {
}
}
// NewDefaultCron returns the default cron implementation for use outside the
// scheduling of a job. For example, validating crontab syntax before passing to the
// NewJob function.
func NewDefaultCron(cronStatementsIncludeSeconds bool) Cron {
return &defaultCron{
withSeconds: cronStatementsIncludeSeconds,
}
}
var _ Cron = (*defaultCron)(nil)
type defaultCron struct {