diff --git a/fixed.go b/fixed.go new file mode 100644 index 0000000..09b62d1 --- /dev/null +++ b/fixed.go @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "time" +) + +type Fixed struct { + duration time.Duration + next time.Time +} + +func NewFixed(duration time.Duration) (*Fixed, error) { + if duration < 0 { + return nil, fmt.Errorf("invalid duration, must be >= 0") + } + return &Fixed{ + duration: duration, + next: time.Now().Add(duration), + }, nil +} + +func (f *Fixed) Next() time.Time { + now := time.Now() + if now.After(f.next) { + f.next = f.next.Add(f.duration) + } + return f.next +} diff --git a/schedule.go b/schedule.go new file mode 100644 index 0000000..964d9e8 --- /dev/null +++ b/schedule.go @@ -0,0 +1,7 @@ +package main + +import "time" + +type Schedule interface { + Next() time.Time +}