Browse Source

cron.WithSeconds: add special constructor for the cron spec variety with seconds

Rob Figueiredo 6 years ago
parent
commit
a851620020
2 changed files with 12 additions and 0 deletions
  1. 4 0
      README.md
  2. 8 0
      option.go

+ 4 - 0
README.md

@@ -25,6 +25,10 @@ Updates required:
   UPDATING: To retain the old behavior, construct your Cron with a custom
   parser:
 
+      // Seconds field, required
+      cron.New(cron.WithSeconds())
+
+      // Seconds field, optional
       cron.New(
           cron.WithParser(
               cron.SecondOptional | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor))

+ 8 - 0
option.go

@@ -15,6 +15,14 @@ func WithLocation(loc *time.Location) Option {
 	}
 }
 
+// WithSeconds overrides the parser used for interpreting job schedules to
+// include a seconds field as the first one.
+func WithSeconds() Option {
+	return WithParser(NewParser(
+		Second | Minute | Hour | Dom | Month | Dow | Descriptor,
+	))
+}
+
 // WithParser overrides the parser used for interpreting job schedules.
 func WithParser(p Parser) Option {
 	return func(c *Cron) {