From 19ce729df1ebcb802076eddfd2f86bdb54f623cc Mon Sep 17 00:00:00 2001 From: Martin Giger Date: Sun, 18 Oct 2020 23:07:54 +0200 Subject: [PATCH 1/2] parse absolute ical timestamps --- pkg/caldav/caldav.go | 1 + pkg/routes/caldav/parsing.go | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/caldav/caldav.go b/pkg/caldav/caldav.go index f58bb9c57..173a6e71c 100644 --- a/pkg/caldav/caldav.go +++ b/pkg/caldav/caldav.go @@ -29,6 +29,7 @@ import ( // DateFormat ist the caldav date format const DateFormat = `20060102T150405` +const DateFormatAbsolute = `20060102T150405Z` // Event holds a single caldav event type Event struct { diff --git a/pkg/routes/caldav/parsing.go b/pkg/routes/caldav/parsing.go index 455e38d71..8298a6d3b 100644 --- a/pkg/routes/caldav/parsing.go +++ b/pkg/routes/caldav/parsing.go @@ -18,6 +18,7 @@ package caldav import ( "strconv" + "strings" "time" "code.vikunja.io/api/pkg/caldav" @@ -111,12 +112,19 @@ func parseTaskFromVTODO(content string) (vTask *models.Task, err error) { return } +// https://tools.ietf.org/html/rfc5545#section-3.3.5 func caldavTimeToTimestamp(tstring string) time.Time { if tstring == "" { return time.Time{} } - t, err := time.Parse(caldav.DateFormat, tstring) + format := caldav.DateFormat + + if strings.HasSuffix(tstring, "Z") { + format = caldav.DateFormatAbsolute + } + + t, err := time.Parse(format, tstring) if err != nil { log.Warningf("Error while parsing caldav time %s to TimeStamp: %s", tstring, err) return time.Time{} -- 2.40.1 From eb22b11d583c049297778f92b29aa524ddc7d917 Mon Sep 17 00:00:00 2001 From: Martin Giger Date: Sun, 18 Oct 2020 23:09:59 +0200 Subject: [PATCH 2/2] no need to export from there I think --- pkg/caldav/caldav.go | 3 +-- pkg/routes/caldav/parsing.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/caldav/caldav.go b/pkg/caldav/caldav.go index 173a6e71c..067a50bae 100644 --- a/pkg/caldav/caldav.go +++ b/pkg/caldav/caldav.go @@ -27,9 +27,8 @@ import ( "code.vikunja.io/api/pkg/utils" ) -// DateFormat ist the caldav date format +// DateFormat is the caldav date format const DateFormat = `20060102T150405` -const DateFormatAbsolute = `20060102T150405Z` // Event holds a single caldav event type Event struct { diff --git a/pkg/routes/caldav/parsing.go b/pkg/routes/caldav/parsing.go index 8298a6d3b..547f717e6 100644 --- a/pkg/routes/caldav/parsing.go +++ b/pkg/routes/caldav/parsing.go @@ -121,7 +121,7 @@ func caldavTimeToTimestamp(tstring string) time.Time { format := caldav.DateFormat if strings.HasSuffix(tstring, "Z") { - format = caldav.DateFormatAbsolute + format = `20060102T150405Z` } t, err := time.Parse(format, tstring) -- 2.40.1