Git Product home page Git Product logo

rrule-go's Introduction

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

rrule-go's People

Contributors

julienbreux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rrule-go's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.