diff --git a/src/internal/converters/ics/ics.go b/src/internal/converters/ics/ics.go index 4b294f42f..3e8277561 100644 --- a/src/internal/converters/ics/ics.go +++ b/src/internal/converters/ics/ics.go @@ -72,6 +72,11 @@ func getLocationString(location models.Locationable) string { } func GetUTCTime(ts, tz string) (time.Time, error) { + var ( + loc *time.Location + err error + ) + // Timezone is always converted to UTC. This is the easiest way to // ensure we have the correct time as the .ics file expects the same // timezone everywhere according to the spec. @@ -80,15 +85,18 @@ func GetUTCTime(ts, tz string) (time.Time, error) { return time.Time{}, clues.Wrap(err, "parsing time").With("given_time_string", ts) } - timezone, ok := GraphTimeZoneToTZ[tz] - if !ok { - return it, clues.New("unknown timezone").With("timezone", tz) - } - - loc, err := time.LoadLocation(timezone) + loc, err = time.LoadLocation(tz) if err != nil { - return time.Time{}, clues.Wrap(err, "loading timezone"). - With("converted_timezone", timezone) + timezone, ok := GraphTimeZoneToTZ[tz] + if !ok { + return it, clues.New("unknown timezone").With("timezone", tz) + } + + loc, err = time.LoadLocation(timezone) + if err != nil { + return time.Time{}, clues.Wrap(err, "loading timezone"). + With("converted_timezone", timezone) + } } // embed timezone diff --git a/src/internal/converters/ics/ics_test.go b/src/internal/converters/ics/ics_test.go index 60649becd..f1434f615 100644 --- a/src/internal/converters/ics/ics_test.go +++ b/src/internal/converters/ics/ics_test.go @@ -138,6 +138,13 @@ func (suite *ICSUnitSuite) TestGetUTCTime() { time: time.Date(2021, 1, 1, 6, 30, 0, 0, time.UTC), errCheck: require.NoError, }, + { + name: "timezone from TZ database", + timestamp: "2021-01-01T12:00:00Z", + timezone: "America/Los_Angeles", + time: time.Date(2021, 1, 1, 20, 0, 0, 0, time.UTC), + errCheck: require.NoError, + }, { name: "invalid time", timestamp: "invalid",