parse absolute ical timestamps

This commit is contained in:
Martin Giger 2020-10-18 23:07:54 +02:00
parent 47486af06d
commit 19ce729df1
Signed by untrusted user: freaktechnik
GPG Key ID: AE530058EFE7FD60
2 changed files with 10 additions and 1 deletions

View File

@ -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 {

View File

@ -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{}