Allow for timezone from TZ database (#5078)

<!-- PR description-->

Graph sometimes just send timezone value which are available in TZ
database. This PR makes sure that we don't always try to convert, but
check if the timezone is already in the format that we need first.

---

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [x] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic
words" - "closes, fixes" to auto-close the Github issue. -->
* #<issue>

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E

---------

Co-authored-by: zackrossman <zrossman@alcion.ai>
This commit is contained in:
Abin Simon 2024-01-23 03:41:39 +05:30 committed by GitHub
parent 9a4a664106
commit deead262ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 8 deletions

View File

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

View File

@ -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",