Calendar recurrence rules in Go.
Basically, implementing the strategy described in Martin Fowler's paper. Read it. It's fun.
Check out the full docs on godoc.org
The Schedule
interface is the foundation of the recurrence package. By using and combining schedules, we can represent all kinds of recurrence rules.
schedule.IsOccurring(time.Time) bool
- does this time.Time
occur in this schedule?
schedule.Occurrences(TimeRange) chan time.Time
- generate time.Time
s occuring with the passed TimeRange
Integer day of the month, 1 through 31, or the constant Last
.
first := recurrence.Day(recurrence.First)
last := recurrence.Day(recurrence.Last)
twentieth := recurrence.Day(20)
Integer week of the month, 1 through 5, or the constant Last
.
first := recurrence.Week(recurrence.First)
last := recurrence.Week(recurrence.Last)
third := recurrence.Week(recurrence.Third)
Day of the week, Sunday through Monday. Constants are defined so you can use them with ease.
recurrence.Sunday.IsOccurring(time.Now())
A month of the year. Constants are defined to be used with ease.
recurrence.January.IsOccurring(time.Now())
A year.
the_future := recurrence.Year(2525)
A range of time. Primarily used as an argument to schedule.Occurrences(t recurrence.TimeRange) chan time.Time
It can also act as a schedule. Any day within the time range is considered as occurring.
forty_days := recurrence.TimeRange{time.Now(), time.Now().AddDate(0, 0, 40)}
Some shortcuts are provided for common time ranges.
recurrence.YearRange(2525)
recurrence.MonthRange(time.January, 2525)
Intersection is a slice of Schedules. IsOccurring
is only satisfied if all members of the slice are true. (Set intersection).
american_thanksgiving := recurrence.Intersection{recurrence.Week(4), recurrence.Thursday, recurrence.November}
Union is a slice of Schedules. IsOccurring
is satisfied if any member of the slice is occurring. (Set union).
weekends := recurrence.Union{recurrence.Saturday, recurrence.Sunday}