rrule-go

Go library for working with recurrence rules for calendar dates.

Github星跟踪图

rrule-go

Go library for working with recurrence rules for calendar dates.

Build Status
Coverage Status
License
GoDoc

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 exampleRRule() {
  fmt.Println("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.Local)})
  fmt.Println(r.All())
  // [1997-09-02 09:00:00 +0800 CST
  // 1997-09-03 09:00:00 +0800 CST
  // ...
  // 1997-09-10 09:00:00 +0800 CST
  // 1997-09-11 09:00:00 +0800 CST]

  fmt.Println(r.Between(
    time.Date(1997, 9, 6, 0, 0, 0, 0, time.Local),
    time.Date(1997, 9, 8, 0, 0, 0, 0, time.Local), true))
  // [1997-09-06 09:00:00 +0800
  // CST 1997-09-07 09:00:00 +0800 CST]

  fmt.Println(r)
  // FREQ=DAILY;DTSTART=19970902T010000Z;COUNT=10
}

rrule.Set

package main

import (
  "fmt"
  "time"

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

func exampleRRuleSet() {
  fmt.Println("\nDaily, 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.Local)})
  set.RRule(r)
  r, _ = rrule.NewRRule(rrule.ROption{
    Freq:      rrule.YEARLY,
    Byweekday: []rrule.Weekday{rrule.SA, rrule.SU},
    Dtstart:   time.Date(1997, 9, 2, 9, 0, 0, 0, time.Local)})
  set.ExRule(r)
  fmt.Println(set.All())
  // [1997-09-02 09:00:00 +0800 CST
  // 1997-09-03 09:00:00 +0800 CST
  // 1997-09-04 09:00:00 +0800 CST
  // 1997-09-05 09:00:00 +0800 CST
  // 1997-09-08 09:00:00 +0800 CST]

  fmt.Println("\nWeekly, 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.Local)})
  set.RRule(r)
  set.RDate(time.Date(1997, 9, 7, 9, 0, 0, 0, time.Local))
  set.ExDate(time.Date(1997, 9, 16, 9, 0, 0, 0, time.Local))
  fmt.Println(set.All())
  // [1997-09-02 09:00:00 +0800 CST
  // 1997-09-07 09:00:00 +0800 CST
  // 1997-09-09 09:00:00 +0800 CST
  // 1997-09-23 09:00:00 +0800 CST]
}

rrule.StrToRRule

func exampleStr() {
  fmt.Println()
  r, _ := rrule.StrToRRule("FREQ=DAILY;INTERVAL=10;COUNT=5")
  fmt.Println(r.All())
  // [2017-03-15 14:12:02 +0800 CST
  // 2017-03-25 14:12:02 +0800 CST
  // 2017-04-04 14:12:02 +0800 CST
  // 2017-04-14 14:12:02 +0800 CST
  // 2017-04-24 14:12:02 +0800 CST]
}

For more examples see python-dateutil documentation.

License

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

主要指标

概览
名称与所有者teambition/rrule-go
主编程语言Go
编程语言Go (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2016-11-26 02:11:10
推送于2024-08-15 00:01:30
最后一次提交2023-04-01 20:53:05
发布数24
最新版本名称v1.8.2 (发布于 )
第一版名称v1.0.0 (发布于 )
用户参与
星数330
关注者数12
派生数59
提交数98
已启用问题?
问题数33
打开的问题数3
拉请求数25
打开的拉请求数3
关闭的拉请求数7
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?