respect the timezone from the ical event#2361
Merged
kodiakhq[bot] merged 5 commits intocalcom:mainfrom Apr 4, 2022
Merged
Conversation
|
@buschco is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
|
This pull request is being automatically deployed with Vercel (learn more). docs – ./apps/docs🔍 Inspect: https://vercel.com/cal/docs/FyQc4A95zo5GkEm6Zfrwar7nW9Dg [Deployment for 34f8018 canceled] calendso – ./apps/web🔍 Inspect: https://vercel.com/cal/calendso/F3pjgLyTRXgSjRai7syDLMLExY41 |
df06ddb to
ab51eda
Compare
Contributor
|
Also @alannnc you're working on something similar right? |
emrysal
approved these changes
Apr 4, 2022
Contributor
|
🤯 Timezones weren't taken into account at all! Good fix 👍 |
joeauyeung
added a commit
that referenced
this pull request
Apr 6, 2022
This reverts commit 2d6cb1e.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixing offsets caused by timezone reasons
Digging down, I found that the calendar service ignores timezones form the calendar events.
I looked into the implementation of
ical.jsto find out how they handle timezones, since I was not able to find anything inCalendarService.They will use
toUnixTimewhich will subtract the UTC offset fromutc_offset-> https://github.com/mozilla-comm/ical.js/blob/ba8e2522ffd30ffbe65197a96a487689d6e6e9a1/lib/ical/time.js#L736-L747
-> https://github.com/mozilla-comm/ical.js/blob/ba8e2522ffd30ffbe65197a96a487689d6e6e9a1/lib/ical/time.js#L685-L692
This offset will be 0 if the timezone matches the local timezone or the UTC timezone. Otherwise they try to find the offset by the registered timezone. Since we haven't registered any timezone, I suppose the offset will also be 0:
So when
ical.jscreates a new date from the ical data and it wont have the timezone since we never registered it. This results in a Date that is in local time but is labeled as UTC.Potential fixes
Register timezones
We could fix this by registering the timezones according to the
ical.js[documentation])(https://github.com/mozilla-comm/ical.js#timezones). I am not happy with this solution because first, the documentation says we can useical.timezones.js, however, I was not able to find this (looked into the node_module and on npm). Also it seems the typedefintions are not well resulting in// @ts-ignores.use dayjs
I prefer this one, since it seems like dayjs is the goto way handling timezone related challenges.
Fixes
Type of change
How should this be tested?
The only way I could reproduce this issue, is by setting the
TZvariable:TZ='UTC' yarn dxfound here -> https://stackoverflow.com/questions/8083410/how-can-i-set-the-default-timezone-in-node-js
I was never able to reproduce this without on my mac. Seems like the vercel servers are using UTC then.
You also need a Calendar in a different timezone than UTC.
Checklist