From 9add9d6595afda50644e64c8a88e728413b9218a Mon Sep 17 00:00:00 2001 From: psic4t Date: Thu, 18 Apr 2024 10:49:16 +0200 Subject: [PATCH] First support for UNTIL --- defines.go | 1 + parse.go | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/defines.go b/defines.go index 1e0a81b..7aea2c0 100644 --- a/defines.go +++ b/defines.go @@ -40,6 +40,7 @@ const ( RFC822 = "02.01.06 15:04" // ics date format ( describes a whole day) IcsFormat = "20060102T150405" + IcsFormatZ = "20060102T150405Z" IcsFormatTZ = "TZID=MST:20060102T150405" //IcsFormatTZ = "20060102T150405Z -0700" IcsFormatWholeDay = "20060102" diff --git a/parse.go b/parse.go index 5a46b6d..53a5f09 100644 --- a/parse.go +++ b/parse.go @@ -205,6 +205,12 @@ func parseEventFreq(eventData *string) string { return trimField(result, `(FREQ=|;)`) } +func parseEventUntil(eventData *string) string { + re, _ := regexp.Compile(`UNTIL=(\d)*T(\d)*Z(;){0,1}`) + result := re.FindString(*eventData) + return trimField(result, `(UNTIL=|;)`) +} + func parseICalTimezone(eventData *string) time.Location { re, _ := regexp.Compile(`X-WR-TIMEZONE:.*?\n`) result := re.FindString(*eventData) @@ -225,6 +231,7 @@ func parseMain(eventData *string, elementsP *[]Event, href, color string) { eventStart, tzId := parseEventStart(eventData) eventEnd, tzId := parseEventEnd(eventData) eventDuration := parseEventDuration(eventData) + eventUntil := parseEventUntil(eventData) freq := parseEventFreq(eventData) if eventEnd.Before(eventStart) { @@ -284,9 +291,15 @@ func parseMain(eventData *string, elementsP *[]Event, href, color string) { eventStart = eventStart.AddDate(years, months, days) eventEnd = eventEnd.AddDate(years, months, days) - // TODO: support UNTIL if eventStart.After(end) { break } + + if eventUntil != "" { + until, _ := time.Parse(IcsFormatZ, eventUntil) + if until.Before(start) { + break + } + } } } -- 2.45.2