All Projects → JulienBreux → rrule-go

JulienBreux / rrule-go

Licence: MIT license
Go library for working with recurrence rules for calendar dates.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to rrule-go

Rrule
JavaScript library for working with recurrence rules for calendar dates as defined in the iCalendar RFC and more.
Stars: ✭ 2,249 (+9678.26%)
Mutual labels:  rrule, recurrence-rules, icalendar-rfc
rrule
🔁 Recurrence rule parsing & calculation as defined in the iCalendar RFC
Stars: ✭ 31 (+34.78%)
Mutual labels:  rrule, recurrence-rules
rfc5545-rrule
RFC5545 RRule library for JavaScript
Stars: ✭ 22 (-4.35%)
Mutual labels:  rrule

rrule.go

Build Status Coverage Status

Go library for working with recurrence rules for calendar dates.

Inspired by the amazing rrule.js.


Quick Start

Installation

The only requirement is the Go Programming Language, at least 1.8

$ go get github.com/JulienBreux/rrule

Overview

RRule
// Create a rule
rule := rrule.RRule{
	freq:      rrule.WEEKLY,
	interval:  5,
	byweekday: [rrule.MO, rrule.FR],
	dtstart:   time.Date(2017, time.January, 1, 10, 30, 0, 0, time.UTC),
	until:     time.Date(2017, time.December, 31, 10, 30, 0, 0, time.UTC),
}

// Get all occurrence dates (Date instances)
rule.All()

// Get a slice of occurrence dates (Date instances)
rule.Between(
	time.Date(2017, time.August, 1, 10, 30, 0, 0, time.UTC),
	time.Date(2017, time.September, 1, 10, 30, 0, 0, time.UTC),
)

// Get an iCalendar RRULE string representation:
// The output can be used with RRule.FromString("...").
rule.ToString()
RRuleSet
// Create a rule set
set := rrule.RRuleSet{}

// Add a rule to set
set.RRule(
	rrule.RRule{
		freq:    rrule.MONTHLY,
		count:   2,
		dtstart: time.Date(2017, time.January, 1, 10, 30, 0, 0, time.UTC),
	}
)

// Add an exclusion rule to set
set.ExRule(
	rrule.RRule{
		freq:    rrule.MONTHLY,
		count:   2,
		dtstart: time.Date(2017, time.February, 1, 10, 30, 0, 0, time.UTC),
	}
)

// Add a date to set
set.RDate(time.Date(2017, time.June, 1, 10, 30, 0, 0, time.UTC))

// Add an another date to set
set.RDate(time.Date(2017, time.June, 2, 10, 30, 0, 0, time.UTC))

// Add an exclusion date to set
set.ExDate(time.Date(2017, time.May, 1, 10, 30, 0, 0, time.UTC))

// Get all occurrence dates (Date instances)
set.All()

// Get a slice of occurrence dates (Date instances)
set.Between(
	time.Date(2017, time.February, 1, 10, 30, 0, 0, time.UTC),
	time.Date(2017, time.June, 2, 10, 30, 0, 0, time.UTC),
)

// Array of strings (e.g. ["RRULE:...", "RDATE:...", "EXRULE:...", "EXDATE:..."])
set.ValueOf()

// To string (array stringified) (e.g. "["RRULE:...", "RDATE:...", "EXRULE:...", "EXDATE:..."]")
set.ToString()
RRule parser
// Parse a RRule string, to a RRule instance
rrule.StrToRule("RRULE:FREQ=MONTHLY;COUNT=5;DTSTART=20170201T023000Z")

// Parse a RRule string, to a RRuleSet instance
rrule.StrToRuleSet("RRULE:FREQ=MONTHLY;COUNT=5;DTSTART=20170201T023000Z")

// Parse a RRuleSet string, to a RRuleSet instance
rrule.StrToRuleSet(
	"RRULE:FREQ=MONTHLY;COUNT=5;DTSTART=20170201T023000Z\n"+
		"RDATE:20170701T023000Z,20170702T023000Z\n"+
		"EXRULE:FREQ=MONTHLY;COUNT=2;DTSTART=20170301T023000Z\n"+
		"EXDATE:20170601T023000Z")

Authors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].