forked from robfig/cron
-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Summary
Allow users to inject a custom time.Now() function for testing and special use cases.
Background
Reference: robfig/cron PR robfig#549
Currently, the scheduler always uses time.Now(). This makes testing time-dependent behavior difficult without actually waiting.
Proposed Solution
Add a functional option:
func WithClock(clock func() time.Time) Option {
return func(c *Cron) {
c.clock = clock
}
}Considerations
WithLocation()covers most timezone use cases- Adds API complexity
- Low demand from users
- Reconsider if user demand increases
Use Cases
- Unit testing scheduled job execution
- Simulating time jumps for DST testing
- Replaying historical schedules
Metadata
Metadata
Assignees
Labels
No labels