mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-04-30 08:25:58 -05:00
fix(caldav): parse timestamps in configured timezone
This commit is contained in:
committed by
kolaente
parent
a160048cc3
commit
0ca26dbf17
@@ -491,23 +491,20 @@ func caldavTimeToTimestamp(ianaProperty ics.IANAProperty) time.Time {
|
|||||||
var err error
|
var err error
|
||||||
tzParameter := ianaProperty.ICalParameters["TZID"]
|
tzParameter := ianaProperty.ICalParameters["TZID"]
|
||||||
if len(tzParameter) > 0 {
|
if len(tzParameter) > 0 {
|
||||||
loc, err := time.LoadLocation(tzParameter[0])
|
loc, locErr := time.LoadLocation(tzParameter[0])
|
||||||
if err != nil {
|
if locErr != nil {
|
||||||
log.Warningf("Error while parsing caldav timezone %s: %s", tzParameter[0], err)
|
log.Warningf("Error while parsing caldav timezone %s: %s", tzParameter[0], locErr)
|
||||||
} else {
|
} else {
|
||||||
t, err = time.ParseInLocation(format, tstring, loc)
|
t, err = time.ParseInLocation(format, tstring, loc)
|
||||||
if err != nil {
|
|
||||||
log.Warningf("Error while parsing caldav time %s to TimeStamp: %s at location %s", tstring, loc, err)
|
|
||||||
} else {
|
|
||||||
t = t.In(config.GetTimeZone())
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
t, err = time.ParseInLocation(format, tstring, config.GetTimeZone())
|
||||||
}
|
}
|
||||||
t, err = time.Parse(format, tstring)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warningf("Error while parsing caldav time %s to TimeStamp: %s", tstring, err)
|
log.Warningf("Error while parsing caldav time %s to TimeStamp: %s", tstring, err)
|
||||||
return time.Time{}
|
return time.Time{}
|
||||||
}
|
}
|
||||||
return t
|
|
||||||
|
return t.In(config.GetTimeZone())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
|
ics "github.com/arran4/golang-ical"
|
||||||
"gopkg.in/d4l3k/messagediff.v1"
|
"gopkg.in/d4l3k/messagediff.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -717,3 +718,15 @@ END:VCALENDAR`,
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCaldavTimeToTimestamp_NoTZID(t *testing.T) {
|
||||||
|
config.InitDefaultConfig()
|
||||||
|
prop := ics.IANAProperty{BaseProperty: ics.BaseProperty{Value: "20181201T011204", ICalParameters: map[string][]string{}}}
|
||||||
|
|
||||||
|
got := caldavTimeToTimestamp(prop)
|
||||||
|
want := time.Date(2018, 12, 1, 1, 12, 4, 0, config.GetTimeZone())
|
||||||
|
|
||||||
|
if !got.Equal(want) || got.Location().String() != config.GetTimeZone().String() {
|
||||||
|
t.Fatalf("caldavTimeToTimestamp() = %v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user