Skip to content

Commit e7114cf

Browse files
committed
feat: expose default cron implementation
1 parent f4c6d14 commit e7114cf

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

example_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,14 @@ func ExampleMonthlyJob() {
348348
)
349349
}
350350

351+
func ExampleNewDefaultCron() {
352+
c := gocron.NewDefaultCron(true)
353+
err := c.IsValid("* * * * * *", time.Local, time.Now())
354+
if err != nil {
355+
panic(err)
356+
}
357+
}
358+
351359
func ExampleNewScheduler() {
352360
s, _ := gocron.NewScheduler()
353361
defer func() { _ = s.Shutdown() }()

job.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ func newDefaultCronImplementation(withSeconds bool) Cron {
140140
}
141141
}
142142

143+
// NewDefaultCron returns the default cron implementation for use outside the
144+
// scheduling of a job. For example, validating crontab syntax before passing to the
145+
// NewJob function.
146+
func NewDefaultCron(cronStatementsIncludeSeconds bool) Cron {
147+
return &defaultCron{
148+
withSeconds: cronStatementsIncludeSeconds,
149+
}
150+
}
151+
143152
var _ Cron = (*defaultCron)(nil)
144153

145154
type defaultCron struct {

0 commit comments

Comments
 (0)