26 lines
439 B
26 lines
439 B
package themis
|
|
|
|
import "time"
|
|
|
|
const ScheduledGameDay = time.Wednesday
|
|
|
|
var defaultClock Clock = DefaultClock{}
|
|
|
|
type Clock interface {
|
|
Now() time.Time
|
|
}
|
|
|
|
type DefaultClock struct{}
|
|
|
|
func (DefaultClock) Now() time.Time {
|
|
return time.Now()
|
|
}
|
|
|
|
func NextOfWeekday(clock Clock, weekday time.Weekday) time.Time {
|
|
if clock == nil {
|
|
clock = defaultClock
|
|
}
|
|
now := clock.Now()
|
|
return now.AddDate(0, 0, int(((7+weekday)-now.Weekday())%7))
|
|
}
|