option.go 848 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package cron
  2. import (
  3. "log"
  4. "time"
  5. )
  6. // Option represents a modification to the default behavior of a Cron.
  7. type Option func(*Cron)
  8. // WithLocation overrides the timezone of the cron instance.
  9. func WithLocation(loc *time.Location) Option {
  10. return func(c *Cron) {
  11. c.location = loc
  12. }
  13. }
  14. // WithSeconds overrides the parser used for interpreting job schedules to
  15. // include a seconds field as the first one.
  16. func WithSeconds() Option {
  17. return WithParser(NewParser(
  18. Second | Minute | Hour | Dom | Month | Dow | Descriptor,
  19. ))
  20. }
  21. // WithParser overrides the parser used for interpreting job schedules.
  22. func WithParser(p Parser) Option {
  23. return func(c *Cron) {
  24. c.parser = p
  25. }
  26. }
  27. // WithPanicLogger overrides the logger used for logging job panics.
  28. func WithPanicLogger(l *log.Logger) Option {
  29. return func(c *Cron) {
  30. c.logger = l
  31. }
  32. }