From 7a1855ef7ac070ed5ff2fa522b210e52205577e7 Mon Sep 17 00:00:00 2001 From: John Roesler Date: Wed, 10 Dec 2025 13:57:36 -0600 Subject: [PATCH] feat: expose default cron implementation (#906) --- example_test.go | 8 ++++++++ job.go | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/example_test.go b/example_test.go index 341ea2a..310fb43 100644 --- a/example_test.go +++ b/example_test.go @@ -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() }() diff --git a/job.go b/job.go index 4a5295c..67930e2 100644 --- a/job.go +++ b/job.go @@ -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 {