From 94d96497b55ba7d3fd2fb8be69ff4b593cf5e7bb Mon Sep 17 00:00:00 2001 From: Serge Bazanski Date: Fri, 22 Sep 2023 20:52:23 +0000 Subject: [PATCH] hswaw/site: implement recurring events Change-Id: Ib3c570d058141c4d8441801010f0f1755ccfc0e7 Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1624 Reviewed-by: radex --- go.mod | 1 + go.sum | 2 ++ hswaw/site/calendar/BUILD.bazel | 1 + hswaw/site/calendar/load.go | 37 +++++++++++++++++++++++++++++++++ third_party/go/repositories.bzl | 7 +++++++ 5 files changed, 48 insertions(+) diff --git a/go.mod b/go.mod index f46fcd98..8e323ad5 100644 --- a/go.mod +++ b/go.mod @@ -92,6 +92,7 @@ require ( github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 + github.com/teambition/rrule-go v1.8.2 github.com/ulule/limiter/v3 v3.11.2 github.com/ziutek/telnet v0.0.0-20180329124119-c3b780dc415b golang.org/x/crypto v0.11.0 diff --git a/go.sum b/go.sum index f1bedc68..359fc854 100644 --- a/go.sum +++ b/go.sum @@ -1307,6 +1307,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= +github.com/teambition/rrule-go v1.8.2 h1:lIjpjvWTj9fFUZCmuoVDrKVOtdiyzbzc93qTmRVe/J8= +github.com/teambition/rrule-go v1.8.2/go.mod h1:Ieq5AbrKGciP1V//Wq8ktsTXwSwJHDD5mD/wLBGl3p4= github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= diff --git a/hswaw/site/calendar/BUILD.bazel b/hswaw/site/calendar/BUILD.bazel index aae6731a..6306e6bf 100644 --- a/hswaw/site/calendar/BUILD.bazel +++ b/hswaw/site/calendar/BUILD.bazel @@ -12,6 +12,7 @@ go_library( deps = [ "@com_github_arran4_golang_ical//:golang-ical", "@com_github_golang_glog//:glog", + "@com_github_teambition_rrule_go//:rrule-go", ], ) diff --git a/hswaw/site/calendar/load.go b/hswaw/site/calendar/load.go index f9ae146d..177ddc88 100644 --- a/hswaw/site/calendar/load.go +++ b/hswaw/site/calendar/load.go @@ -12,6 +12,7 @@ import ( ics "github.com/arran4/golang-ical" "github.com/golang/glog" + rrule "github.com/teambition/rrule-go" ) const ( @@ -94,6 +95,42 @@ func parseUpcomingEvents(now time.Time, data io.Reader) ([]*UpcomingEvent, error glog.Errorf("Event %s has whole-day inconsistencies, start: %s, end: %s, ignoring", uid, start, end) } + rruleS := event.GetProperty(ics.ComponentPropertyRrule) + if rruleS != nil { + rrule, err := rrule.StrToRRule(rruleS.Value) + if err != nil { + glog.Errorf("Event %s has unparseable RRULE, ignoring: %v", uid, err) + continue + } + rrule.DTStart(start.Time) + + duration := end.Time.Sub(start.Time) + if start.WholeDay { + duration = time.Hour * 24 + } + + next := rrule.After(now, true) + if next.IsZero() { + continue + } + u := &UpcomingEvent{ + UID: uid, + Summary: summary, + Description: description, + Start: &EventTime{ + Time: next, + WholeDay: start.WholeDay, + }, + End: &EventTime{ + Time: next.Add(duration), + WholeDay: start.WholeDay, + }, + Tentative: tentative, + } + out = append(out, u) + continue + } + u := &UpcomingEvent{ UID: uid, Summary: summary, diff --git a/third_party/go/repositories.bzl b/third_party/go/repositories.bzl index 9df4bf73..3934e42f 100644 --- a/third_party/go/repositories.bzl +++ b/third_party/go/repositories.bzl @@ -3802,6 +3802,13 @@ def go_repositories(): sum = "h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=", version = "v0.0.0-20200815063812-42c35b437635", ) + go_repository( + name = "com_github_teambition_rrule_go", + importpath = "github.com/teambition/rrule-go", + sum = "h1:lIjpjvWTj9fFUZCmuoVDrKVOtdiyzbzc93qTmRVe/J8=", + version = "v1.8.2", + ) + go_repository( name = "com_github_technoweenie_multipartstreamer", importpath = "github.com/technoweenie/multipartstreamer",