Skip to content

Commit

Permalink
outlook: correctly create events using UTC timezone
Browse files Browse the repository at this point in the history
When creating an event, the timestamp's timezone was silently dropped and
replaced with the timezone of the local system. Timestamps returned by
outlook are in UTC, such that syncing from outlook to outlook resulted
in shifted events on non-UTC systems.

Explicitly convert timestamps to UTC to ensure correctness.
  • Loading branch information
MichaelEischer committed Oct 10, 2024
1 parent 7e7d652 commit 01a0f10
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
github.com/microcosm-cc/bluemonday v1.0.27
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/stretchr/testify v1.9.0
github.com/thlib/go-timezone-local v0.0.3
github.com/urfave/cli/v2 v2.27.2
go.uber.org/ratelimit v0.3.1
golang.org/x/oauth2 v0.22.0
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8
github.com/teambition/rrule-go v1.7.2/go.mod h1:mBJ1Ht5uboJ6jexKdNUJg2NcwP8uUMNvStWXlJD3MvU=
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/thlib/go-timezone-local v0.0.3 h1:ie5XtZWG5lQ4+1MtC5KZ/FeWlOKzW2nPoUnXYUbV/1s=
github.com/thlib/go-timezone-local v0.0.3/go.mod h1:/Tnicc6m/lsJE0irFMA0LfIwTBo4QP7A8IfyIv4zZKI=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
Expand Down Expand Up @@ -171,7 +169,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Expand Down
15 changes: 4 additions & 11 deletions internal/adapter/outlook_http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"time"

"github.com/charmbracelet/log"
"github.com/thlib/go-timezone-local/tzlocal"

"github.com/inovex/CalendarSync/internal/models"
)
Expand Down Expand Up @@ -190,16 +189,10 @@ func (o OutlookClient) eventToOutlookEvent(e models.Event) (oe Event) {
outlookEvent := Event{}
outlookEvent.Location.Name = e.Location

// microsoft expects iana time zone codes, but the go standard library returns abbreviations like "CET"
// NOTE: This may not work when events get imported from other time zones, i would expect golang to properly format the time strings correctly using the local runtime timezone
tzname, err := tzlocal.RuntimeTZ()
if err != nil {
tzname = "UTC"
}
outlookEvent.Start.DateTime = e.StartTime.Format(timeFormat)
outlookEvent.Start.TimeZone = tzname
outlookEvent.End.DateTime = e.EndTime.Format(timeFormat)
outlookEvent.End.TimeZone = tzname
outlookEvent.Start.DateTime = e.StartTime.UTC().Format(timeFormat)
outlookEvent.Start.TimeZone = "UTC"
outlookEvent.End.DateTime = e.EndTime.UTC().Format(timeFormat)
outlookEvent.End.TimeZone = "UTC"

outlookEvent.Subject = e.Title
outlookEvent.ID = e.ID
Expand Down

0 comments on commit 01a0f10

Please sign in to comment.