rrule-go
Go library for working with recurrence rules for calendar dates.

The rrule module offers a complete implementation of the recurrence rules documented in the iCalendar
RFC. It is a partial port of the rrule module from the excellent python-dateutil library.
Demo
rrule.RRule
package main
import (
"fmt"
"time"
"github.com/teambition/rrule-go"
)
func printTimeSlice(ts []time.Time) {
for _, t := range ts {
fmt.Println(t)
}
}
func main() {
r, _ := rrule.NewRRule(rrule.ROption{
Freq: rrule.DAILY,
Count: 10,
Dtstart: time.Date(1997, 9, 2, 9, 0, 0, 0, time.UTC),
})
fmt.Println(r.String())
printTimeSlice(r.All())
printTimeSlice(r.Between(
time.Date(1997, 9, 6, 0, 0, 0, 0, time.UTC),
time.Date(1997, 9, 8, 0, 0, 0, 0, time.UTC), true))
r, _ = rrule.NewRRule(rrule.ROption{
Freq: rrule.YEARLY,
Interval: 4,
Count: 3,
Bymonth: []int{11},
Byweekday: []rrule.Weekday{rrule.TU},
Bymonthday: []int{2, 3, 4, 5, 6, 7, 8},
Dtstart: time.Date(1996, 11, 5, 9, 0, 0, 0, time.UTC),
})
fmt.Println(r.String())
printTimeSlice(r.All())
}
rrule.Set
func ExampleSet() {
set := rrule.Set{}
r, _ := rrule.NewRRule(rrule.ROption{
Freq: rrule.DAILY,
Count: 7,
Dtstart: time.Date(1997, 9, 2, 9, 0, 0, 0, time.UTC)})
set.RRule(r)
fmt.Println(set.String())
printTimeSlice(set.All())
set = rrule.Set{}
r, _ = rrule.NewRRule(rrule.ROption{
Freq: rrule.WEEKLY,
Count: 4,
Dtstart: time.Date(1997, 9, 2, 9, 0, 0, 0, time.UTC)})
set.RRule(r)
set.RDate(time.Date(1997, 9, 7, 9, 0, 0, 0, time.UTC))
set.ExDate(time.Date(1997, 9, 16, 9, 0, 0, 0, time.UTC))
fmt.Println(set.String())
printTimeSlice(set.All())
}
rrule.StrToRRule
func ExampleStrToRRule() {
r, _ := rrule.StrToRRule("FREQ=DAILY;DTSTART=20060101T150405Z;COUNT=5")
fmt.Println(r.OrigOptions.RRuleString())
fmt.Println(r.OrigOptions.String())
fmt.Println(r.String())
printTimeSlice(r.All())
}
rrule.StrToRRuleSet
func ExampleStrToRRuleSet() {
s, _ := rrule.StrToRRuleSet("DTSTART:20060101T150405Z\nRRULE:FREQ=DAILY;COUNT=5\nEXDATE:20060102T150405Z")
fmt.Println(s.String())
printTimeSlice(s.All())
}
For more examples see python-dateutil documentation.
License
Gear is licensed under the MIT license.
Copyright © 2017-2023 Teambition.