rrule

package module
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

This is a maintained fork of teambition/rrule-go. The original project is no longer maintained. This is a modified copy with Go 1.16 support. The v1.9.0 candidate uses module path github.com/kentonium3/rrule-go. Existing callers must change imports, and external positional ROption literals must use keyed fields. See MIGRATION.md before upgrading.

RFC 5545 is the reference for how rules behave. Where the original code or python-dateutil differs from it, this fork follows the RFC.

Changes in the v1.9.0 candidate

Generated daylight-saving gap times are skipped before COUNT and BYSETPOS, and folds choose the first occurrence. Parsed floating and DATE values retain their forms; explicit DTSTART/UNTIL pairs are validated. Repeated time selectors no longer duplicate occurrences. The changelog describes the behavior changes and credits, and the migration guide covers imports, replacements, keyed ROption literals and parsing compatibility.

These are candidate changes until the public v1.9.0 tag is published.

Fixes released in v1.8.3

  • Panics on accepted rules. BYDAY ordinals outside the month, BYEASTER offsets outside the year, and very large INTERVAL values could make the iterator panic with "index out of range". They now either yield no occurrence for the impossible parts or stop safely.
  • A hang. HOURLY, MINUTELY and SECONDLY rules whose BYHOUR, BYMINUTE or BYSECOND values can't be reached from DTSTART at the given INTERVAL looped forever. They now finish with no occurrence.
  • Long scans with UNTIL (UTC only). When DTSTART is in UTC, a rule that never matches now stops at UNTIL instead of scanning to the year 9999. Other locations behave as before.

The v1.8.3 fixes preserve occurrences for rules that worked before that release. They come with regression tests and a fuzz test.

See CHANGELOG.md for released and unreleased changes.

Roadmap

See ROADMAP.md for project priorities, sequencing, and the distinction between RFC 5545 behavior and useful scheduling extensions.

Maintainer and help wanted

This fork is maintained by Kent Gale (@kentonium3).

Co-maintainer wanted. Kent is looking for an experienced Go developer to help share ongoing maintenance: reviewing changes, investigating bugs, improving tests, and shaping releases. Experience with recurrence rules, calendar standards, or timezones would be especially useful.

Issue-triage contributors are welcome, too. If a full co-maintainer role is more than you want to take on, help reproducing reports, reducing test cases, identifying duplicates, clarifying expected behavior, and proposing labels or milestones would be valuable. This can be a smaller, focused contribution; responsibilities and repository access can be agreed individually.

To express interest in either role, open an issue with a short introduction, your relevant experience, and the kind of help you would like to offer. Small contributions are welcome.

Using it

For v1.9.0, import github.com/kentonium3/rrule-go (package name rrule). Once that public tag is published:

go get github.com/kentonium3/rrule-go@v1.9.0
go mod tidy

Existing users must follow MIGRATION.md before removing old-path replacements. Until publication, the released v1.8.3 arrangement remains:

go mod edit -replace github.com/teambition/rrule-go=github.com/kentonium3/rrule-go@v1.8.3
go mod tidy

That v1.8.3 arrangement uses imports of github.com/teambition/rrule-go.

Report problems in this repository's issues. Licensed under MIT, as the original (© Teambition).


rrule-go

Go library for working with recurrence rules for calendar dates.

CI CodeQL License Go Reference

The rrule module implements the recurrence rules of the iCalendar standard, RFC 5545. It began as a partial port of the rrule module from the excellent python-dateutil library.

Demo

rrule.RRule

package main

import (
  "fmt"
  "time"

  "github.com/kentonium3/rrule-go"
)

func printTimeSlice(ts []time.Time) {
	for _, t := range ts {
		fmt.Println(t)
	}
}

func main() {
	// Daily, for 10 occurrences.
	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())
	// DTSTART:19970902T090000Z
	// RRULE:FREQ=DAILY;COUNT=10

	printTimeSlice(r.All())
	// 1997-09-02 09:00:00 +0000 UTC
	// 1997-09-03 09:00:00 +0000 UTC
	// ...
	// 1997-09-07 09:00:00 +0000 UTC

	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))
	// [1997-09-06 09:00:00 +0000 UTC
	//  1997-09-07 09:00:00 +0000 UTC]

	// Every four years, the first Tuesday after a Monday in November, 3 occurrences (U.S. Presidential Election day).
	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())
	// DTSTART:19961105T090000Z
	// RRULE:FREQ=YEARLY;INTERVAL=4;COUNT=3;BYMONTH=11;BYMONTHDAY=2,3,4,5,6,7,8;BYDAY=TU

	printTimeSlice(r.All())
	// 1996-11-05 09:00:00 +0000 UTC
	// 2000-11-07 09:00:00 +0000 UTC
	// 2004-11-02 09:00:00 +0000 UTC
}

rrule.Set

func ExampleSet() {
	// Daily, for 7 days, jumping Saturday and Sunday occurrences.
	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())
	// DTSTART:19970902T090000Z
	// RRULE:FREQ=DAILY;COUNT=7

	printTimeSlice(set.All())
	// 1997-09-02 09:00:00 +0000 UTC
	// 1997-09-03 09:00:00 +0000 UTC
	// 1997-09-04 09:00:00 +0000 UTC
	// 1997-09-05 09:00:00 +0000 UTC
	// 1997-09-06 09:00:00 +0000 UTC
	// 1997-09-07 09:00:00 +0000 UTC
	// 1997-09-08 09:00:00 +0000 UTC

	// Weekly, for 4 weeks, plus one time on day 7, and not on day 16.
	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())
	// DTSTART:19970902T090000Z
	// RRULE:FREQ=WEEKLY;COUNT=4
	// RDATE:19970907T090000Z
	// EXDATE:19970916T090000Z

	printTimeSlice(set.All())
	// 1997-09-02 09:00:00 +0000 UTC
	// 1997-09-07 09:00:00 +0000 UTC
	// 1997-09-09 09:00:00 +0000 UTC
	// 1997-09-23 09:00:00 +0000 UTC
}

rrule.StrToRRule

func ExampleStrToRRule() {
	// Compatible with old DTSTART
	r, _ := rrule.StrToRRule("FREQ=DAILY;DTSTART=20060101T150405Z;COUNT=5")
	fmt.Println(r.OrigOptions.RRuleString())
	// FREQ=DAILY;COUNT=5

	fmt.Println(r.OrigOptions.String())
	// DTSTART:20060101T150405Z
	// RRULE:FREQ=DAILY;COUNT=5

	fmt.Println(r.String())
	// DTSTART:20060101T150405Z
	// RRULE:FREQ=DAILY;COUNT=5

	printTimeSlice(r.All())
	// 2006-01-01 15:04:05 +0000 UTC
	// 2006-01-02 15:04:05 +0000 UTC
	// 2006-01-03 15:04:05 +0000 UTC
	// 2006-01-04 15:04:05 +0000 UTC
	// 2006-01-05 15:04:05 +0000 UTC
}

rrule.StrToRRuleSet

func ExampleStrToRRuleSet() {
	s, _ := rrule.StrToRRuleSet("DTSTART:20060101T150405Z\nRRULE:FREQ=DAILY;COUNT=5\nEXDATE:20060102T150405Z")
	fmt.Println(s.String())
	// DTSTART:20060101T150405Z
	// RRULE:FREQ=DAILY;COUNT=5
	// EXDATE:20060102T150405Z

	printTimeSlice(s.All())
	// 2006-01-01 15:04:05 +0000 UTC
	// 2006-01-03 15:04:05 +0000 UTC
	// 2006-01-04 15:04:05 +0000 UTC
	// 2006-01-05 15:04:05 +0000 UTC
}

For more examples see python-dateutil documentation.

License

Gear is licensed under the MIT license. Copyright © 2017-2023 Teambition.

Documentation

Index

Examples

Constants

View Source
const (
	// DateTimeFormat is date-time format used in iCalendar (RFC 5545)
	DateTimeFormat = "20060102T150405Z"
	// LocalDateTimeFormat is a date-time format without Z prefix
	LocalDateTimeFormat = "20060102T150405"
	// DateFormat is date format used in iCalendar (RFC 5545)
	DateFormat = "20060102"
)
View Source
const (
	MAXYEAR = 9999
)

MAXYEAR

Variables

View Source
var (
	M366MASK     []int
	M365MASK     []int
	MDAY366MASK  []int
	MDAY365MASK  []int
	NMDAY366MASK []int
	NMDAY365MASK []int
	WDAYMASK     []int
	M366RANGE    = []int{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}
	M365RANGE    = []int{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}
)

Every mask is 7 days longer to handle cross-year weekly periods.

View Source
var (
	MO = Weekday{/* contains filtered or unexported fields */}
	TU = Weekday{/* contains filtered or unexported fields */}
	WE = Weekday{/* contains filtered or unexported fields */}
	TH = Weekday{/* contains filtered or unexported fields */}
	FR = Weekday{/* contains filtered or unexported fields */}
	SA = Weekday{/* contains filtered or unexported fields */}
	SU = Weekday{/* contains filtered or unexported fields */}
)

Weekdays

Functions

func StrToDates

func StrToDates(str string) (ts []time.Time, err error)

StrToDates is intended to parse RDATE and EXDATE properties supporting only VALUE=DATE-TIME (DATE and PERIOD are not supported). Accepts string with format: "VALUE=DATE-TIME;[TZID=...]:{time},{time},...,{time}" or simply "{time},{time},...{time}" and parses it to array of dates In case no time zone specified in str, when all dates are parsed in UTC

func StrToDatesInLoc

func StrToDatesInLoc(str string, defaultLoc *time.Location) (ts []time.Time, err error)

StrToDatesInLoc same as StrToDates but it consideres default location to parse dates in in case no location specified with TZID parameter

func StrToDtStart

func StrToDtStart(str string, defaultLoc *time.Location) (time.Time, error)

StrToDtStart accepts string with format: "(TZID={timezone}:)?{time}" and parses it to a date may be used to parse DTSTART rules, without the DTSTART; part.

Types

type Frequency

type Frequency int

Frequency denotes the period on which the rule is evaluated.

const (
	YEARLY Frequency = iota
	MONTHLY
	WEEKLY
	DAILY
	HOURLY
	MINUTELY
	SECONDLY
)

Constants

func StrToFreq

func StrToFreq(str string) (Frequency, error)

func (Frequency) String

func (f Frequency) String() string

type Next

type Next func() (value time.Time, ok bool)

Next is a generator of time.Time. It returns false of Ok if there is no value to generate.

type ROption

type ROption struct {
	Freq       Frequency
	Dtstart    time.Time
	Interval   int
	Wkst       Weekday
	Count      int
	Until      time.Time
	Bysetpos   []int
	Bymonth    []int
	Bymonthday []int
	Byyearday  []int
	Byweekno   []int
	Byweekday  []Weekday
	Byhour     []int
	Byminute   []int
	Bysecond   []int
	Byeaster   []int
	// contains filtered or unexported fields
}

ROption offers options to construct a RRule instance. For performance, it is strongly recommended providing explicit ROption.Dtstart, which defaults to `time.Now().UTC().Truncate(time.Second)`.

func StrToROption

func StrToROption(rfcString string) (*ROption, error)

StrToROption converts string to ROption.

func StrToROptionInLocation

func StrToROptionInLocation(rfcString string, loc *time.Location) (*ROption, error)

StrToROptionInLocation is same as StrToROption but in case local time is supplied as date-time/date field (ex. UNTIL), it is parsed as a time in a given location (time zone)

func (*ROption) RRuleString

func (option *ROption) RRuleString() string

RRuleString returns RRULE string exclude DTSTART

func (*ROption) String

func (option *ROption) String() string

String returns RRULE string with DTSTART if exists. e.g.

DTSTART;TZID=America/New_York:19970105T083000
RRULE:FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;BYMINUTE=30

type RRule

type RRule struct {
	OrigOptions ROption
	Options     ROption
	// contains filtered or unexported fields
}

RRule offers a small, complete, and very fast, implementation of the recurrence rules documented in the iCalendar RFC, including support for caching of results.

Example
package main

import (
	"fmt"
	"time"

	"github.com/kentonium3/rrule-go"
)

func printTimeSlice(ts []time.Time) {
	for _, t := range ts {
		fmt.Println(t)
	}
}

func main() {
	// Daily, for 10 occurrences.
	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())
	// DTSTART:19970902T090000Z
	// RRULE:FREQ=DAILY;COUNT=10

	printTimeSlice(r.All())
	// 1997-09-02 09:00:00 +0000 UTC
	// 1997-09-03 09:00:00 +0000 UTC
	// ...
	// 1997-09-07 09:00:00 +0000 UTC

	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))
	// [1997-09-06 09:00:00 +0000 UTC
	//  1997-09-07 09:00:00 +0000 UTC]

	// Every four years, the first Tuesday after a Monday in November, 3 occurrences (U.S. Presidential Election day).
	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())
	// DTSTART:19961105T090000Z
	// RRULE:FREQ=YEARLY;INTERVAL=4;COUNT=3;BYMONTH=11;BYMONTHDAY=2,3,4,5,6,7,8;BYDAY=TU

	printTimeSlice(r.All())
	// 1996-11-05 09:00:00 +0000 UTC
	// 2000-11-07 09:00:00 +0000 UTC
	// 2004-11-02 09:00:00 +0000 UTC

}
Output:
DTSTART:19970902T090000Z
RRULE:FREQ=DAILY;COUNT=10
1997-09-02 09:00:00 +0000 UTC
1997-09-03 09:00:00 +0000 UTC
1997-09-04 09:00:00 +0000 UTC
1997-09-05 09:00:00 +0000 UTC
1997-09-06 09:00:00 +0000 UTC
1997-09-07 09:00:00 +0000 UTC
1997-09-08 09:00:00 +0000 UTC
1997-09-09 09:00:00 +0000 UTC
1997-09-10 09:00:00 +0000 UTC
1997-09-11 09:00:00 +0000 UTC
1997-09-06 09:00:00 +0000 UTC
1997-09-07 09:00:00 +0000 UTC
DTSTART:19961105T090000Z
RRULE:FREQ=YEARLY;INTERVAL=4;COUNT=3;BYMONTH=11;BYMONTHDAY=2,3,4,5,6,7,8;BYDAY=TU
1996-11-05 09:00:00 +0000 UTC
2000-11-07 09:00:00 +0000 UTC
2004-11-02 09:00:00 +0000 UTC

func NewRRule

func NewRRule(arg ROption) (*RRule, error)

NewRRule construct a new RRule instance

func StrToRRule

func StrToRRule(rfcString string) (*RRule, error)

StrToRRule converts string to RRule

Example
package main

import (
	"fmt"
	"time"

	"github.com/kentonium3/rrule-go"
)

func printTimeSlice(ts []time.Time) {
	for _, t := range ts {
		fmt.Println(t)
	}
}

func main() {
	// Compatible with old DTSTART
	r, _ := rrule.StrToRRule("FREQ=DAILY;DTSTART=20060101T150405Z;COUNT=5")
	fmt.Println(r.OrigOptions.RRuleString())
	// FREQ=DAILY;COUNT=5

	fmt.Println(r.OrigOptions.String())
	// DTSTART:20060101T150405Z
	// RRULE:FREQ=DAILY;COUNT=5

	fmt.Println(r.String())
	// DTSTART:20060101T150405Z
	// RRULE:FREQ=DAILY;COUNT=5

	printTimeSlice(r.All())
	// 2006-01-01 15:04:05 +0000 UTC
	// 2006-01-02 15:04:05 +0000 UTC
	// 2006-01-03 15:04:05 +0000 UTC
	// 2006-01-04 15:04:05 +0000 UTC
	// 2006-01-05 15:04:05 +0000 UTC

}
Output:
FREQ=DAILY;COUNT=5
DTSTART:20060101T150405Z
RRULE:FREQ=DAILY;COUNT=5
DTSTART:20060101T150405Z
RRULE:FREQ=DAILY;COUNT=5
2006-01-01 15:04:05 +0000 UTC
2006-01-02 15:04:05 +0000 UTC
2006-01-03 15:04:05 +0000 UTC
2006-01-04 15:04:05 +0000 UTC
2006-01-05 15:04:05 +0000 UTC

func (*RRule) After

func (r *RRule) After(dt time.Time, inc bool) time.Time

After returns the first recurrence after the given datetime instance, or time.Time's zero value if no recurrence match. The inc keyword defines what happens if dt is an occurrence. With inc == True, if dt itself is an occurrence, it will be returned. It is only supported second precision.

func (*RRule) All

func (r *RRule) All() []time.Time

All returns all occurrences of the RRule. It is only supported second precision.

func (*RRule) Before

func (r *RRule) Before(dt time.Time, inc bool) time.Time

Before returns the last recurrence before the given datetime instance, or time.Time's zero value if no recurrence match. The inc keyword defines what happens if dt is an occurrence. With inc == True, if dt itself is an occurrence, it will be returned. It is only supported second precision.

func (*RRule) Between

func (r *RRule) Between(after, before time.Time, inc bool) []time.Time

Between returns all the occurrences of the RRule between after and before. The inc keyword defines what happens if after and/or before are themselves occurrences. With inc == True, they will be included in the list, if they are found in the recurrence set. It is only supported second precision.

func (*RRule) DTStart

func (r *RRule) DTStart(dt time.Time)

DTStart set a new DTSTART for the rule and recalculates the timeset if needed. It will be truncated to second precision. Default to `time.Now().UTC().Truncate(time.Second)`.

func (*RRule) GetDTStart

func (r *RRule) GetDTStart() time.Time

GetDTStart gets DTSTART time for rrule

func (*RRule) GetUntil

func (r *RRule) GetUntil() time.Time

GetUntil gets UNTIL time for rrule

func (*RRule) Iterator

func (r *RRule) Iterator() Next

Iterator return an iterator for RRule

func (*RRule) String

func (r *RRule) String() string

func (*RRule) Until

func (r *RRule) Until(ut time.Time)

Until set a new UNTIL for the rule and recalculates the timeset if needed. It will be truncated to second precision. Default to `Dtstart.Add(time.Duration(1<<63 - 1))`, approximately 290 years.

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set allows more complex recurrence setups, mixing multiple rules, dates, exclusion rules, and exclusion dates

Example
package main

import (
	"fmt"
	"time"

	"github.com/kentonium3/rrule-go"
)

func printTimeSlice(ts []time.Time) {
	for _, t := range ts {
		fmt.Println(t)
	}
}

func main() {
	// Daily, for 7 days, jumping Saturday and Sunday occurrences.
	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())
	// DTSTART:19970902T090000Z
	// RRULE:FREQ=DAILY;COUNT=7

	printTimeSlice(set.All())
	// 1997-09-02 09:00:00 +0000 UTC
	// 1997-09-03 09:00:00 +0000 UTC
	// 1997-09-04 09:00:00 +0000 UTC
	// 1997-09-05 09:00:00 +0000 UTC
	// 1997-09-06 09:00:00 +0000 UTC
	// 1997-09-07 09:00:00 +0000 UTC
	// 1997-09-08 09:00:00 +0000 UTC

	// Weekly, for 4 weeks, plus one time on day 7, and not on day 16.
	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())
	// DTSTART:19970902T090000Z
	// RRULE:FREQ=WEEKLY;COUNT=4
	// RDATE:19970907T090000Z
	// EXDATE:19970916T090000Z

	printTimeSlice(set.All())
	// 1997-09-02 09:00:00 +0000 UTC
	// 1997-09-07 09:00:00 +0000 UTC
	// 1997-09-09 09:00:00 +0000 UTC
	// 1997-09-23 09:00:00 +0000 UTC

}
Output:
DTSTART:19970902T090000Z
RRULE:FREQ=DAILY;COUNT=7
1997-09-02 09:00:00 +0000 UTC
1997-09-03 09:00:00 +0000 UTC
1997-09-04 09:00:00 +0000 UTC
1997-09-05 09:00:00 +0000 UTC
1997-09-06 09:00:00 +0000 UTC
1997-09-07 09:00:00 +0000 UTC
1997-09-08 09:00:00 +0000 UTC
DTSTART:19970902T090000Z
RRULE:FREQ=WEEKLY;COUNT=4
RDATE:19970907T090000Z
EXDATE:19970916T090000Z
1997-09-02 09:00:00 +0000 UTC
1997-09-07 09:00:00 +0000 UTC
1997-09-09 09:00:00 +0000 UTC
1997-09-23 09:00:00 +0000 UTC

func StrSliceToRRuleSet

func StrSliceToRRuleSet(ss []string) (*Set, error)

StrSliceToRRuleSet converts given str slice to RRuleSet In case there is a time met in any rule without specified time zone, when it is parsed in UTC (see StrSliceToRRuleSetInLoc)

func StrSliceToRRuleSetInLoc

func StrSliceToRRuleSetInLoc(ss []string, defaultLoc *time.Location) (*Set, error)

StrSliceToRRuleSetInLoc is same as StrSliceToRRuleSet, but by default parses local times in specified default location

func StrToRRuleSet

func StrToRRuleSet(s string) (*Set, error)

StrToRRuleSet converts string to RRuleSet

Example
package main

import (
	"fmt"
	"time"

	"github.com/kentonium3/rrule-go"
)

func printTimeSlice(ts []time.Time) {
	for _, t := range ts {
		fmt.Println(t)
	}
}

func main() {
	s, _ := rrule.StrToRRuleSet("DTSTART:20060101T150405Z\nRRULE:FREQ=DAILY;COUNT=5\nEXDATE:20060102T150405Z")
	fmt.Println(s.String())
	// DTSTART:20060101T150405Z
	// RRULE:FREQ=DAILY;COUNT=5
	// EXDATE:20060102T150405Z

	printTimeSlice(s.All())
	// 2006-01-01 15:04:05 +0000 UTC
	// 2006-01-03 15:04:05 +0000 UTC
	// 2006-01-04 15:04:05 +0000 UTC
	// 2006-01-05 15:04:05 +0000 UTC

}
Output:
DTSTART:20060101T150405Z
RRULE:FREQ=DAILY;COUNT=5
EXDATE:20060102T150405Z
2006-01-01 15:04:05 +0000 UTC
2006-01-03 15:04:05 +0000 UTC
2006-01-04 15:04:05 +0000 UTC
2006-01-05 15:04:05 +0000 UTC

func (*Set) After

func (set *Set) After(dt time.Time, inc bool) time.Time

After returns the first recurrence after the given datetime instance, or time.Time's zero value if no recurrence match. The inc keyword defines what happens if dt is an occurrence. With inc == True, if dt itself is an occurrence, it will be returned. It is only supported second precision.

func (*Set) All

func (set *Set) All() []time.Time

All returns all occurrences of the rrule.Set. It is only supported second precision.

func (*Set) Before

func (set *Set) Before(dt time.Time, inc bool) time.Time

Before Returns the last recurrence before the given datetime instance, or time.Time's zero value if no recurrence match. The inc keyword defines what happens if dt is an occurrence. With inc == True, if dt itself is an occurrence, it will be returned. It is only supported second precision.

func (*Set) Between

func (set *Set) Between(after, before time.Time, inc bool) []time.Time

Between returns all the occurrences of the rrule between after and before. The inc keyword defines what happens if after and/or before are themselves occurrences. With inc == True, they will be included in the list, if they are found in the recurrence set. It is only supported second precision.

func (*Set) DTStart

func (set *Set) DTStart(dtstart time.Time)

DTStart sets dtstart property for set. It will be truncated to second precision.

func (*Set) ExDate

func (set *Set) ExDate(exdate time.Time)

ExDate include the given datetime instance in the recurrence set exclusion list. Dates included that way will not be generated, even if some inclusive rrule or rdate matches them. It will be truncated to second precision.

func (*Set) GetDTStart

func (set *Set) GetDTStart() time.Time

GetDTStart gets DTSTART for set

func (*Set) GetExDate

func (set *Set) GetExDate() []time.Time

GetExDate returns explicitly excluded dates (exdates) in the set

func (*Set) GetRDate

func (set *Set) GetRDate() []time.Time

GetRDate returns explicitly added dates (rdates) in the set

func (*Set) GetRRule

func (set *Set) GetRRule() *RRule

GetRRule returns the rrules in the set

func (*Set) Iterator

func (set *Set) Iterator() (next func() (time.Time, bool))

Iterator returns an iterator for rrule.Set

func (*Set) RDate

func (set *Set) RDate(rdate time.Time)

RDate include the given datetime instance in the recurrence set generation. It will be truncated to second precision.

func (*Set) RRule

func (set *Set) RRule(rrule *RRule)

RRule set the RRULE for set. There is the only one RRULE in the set as https://tools.ietf.org/html/rfc5545#appendix-A.1

func (*Set) Recurrence

func (set *Set) Recurrence() []string

Recurrence returns a slice of all the recurrence rules for a set

func (*Set) SetExDates

func (set *Set) SetExDates(exdates []time.Time)

SetExDates sets explicitly excluded dates (exdates) in the set. It will be truncated to second precision.

func (*Set) SetRDates

func (set *Set) SetRDates(rdates []time.Time)

SetRDates sets explicitly added dates (rdates) in the set. It will be truncated to second precision.

func (*Set) String

func (set *Set) String() string

type Weekday

type Weekday struct {
	// contains filtered or unexported fields
}

Weekday specifying the nth weekday. Field N could be positive or negative (like MO(+2) or MO(-3). Not specifying N (0) is the same as specifying +1.

func (*Weekday) Day

func (wday *Weekday) Day() int

Day returns index of the day in a week (0 for MO, 6 for SU)

func (*Weekday) N

func (wday *Weekday) N() int

N returns index of the week, e.g. for 3MO, N() will return 3

func (*Weekday) Nth

func (wday *Weekday) Nth(n int) Weekday

Nth return the nth weekday __call__ - Cannot call the object directly, do it through e.g. TH.nth(-1) instead,

func (Weekday) String

func (wday Weekday) String() string

Directories

Path Synopsis
tools
changelog command
Command changelog checks the root changelog and extracts finalized release notes.
Command changelog checks the root changelog and extracts finalized release notes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL