Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iCalendar timezone fix in CalDAV #5091

Merged
merged 3 commits into from
Oct 19, 2022
Merged

iCalendar timezone fix in CalDAV #5091

merged 3 commits into from
Oct 19, 2022

Conversation

alishaz-polymath
Copy link
Member

What does this PR do?

Adds support for timezone change when vTimezone is not provided in the calendar object, but tzid is provided. This is the case with iCalendar, along with a few other service providers.

Fixes #2139

Loom

Environment: Staging(main branch)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • connect apple calendar and mark something busy there
  • Test for the timeslot in Cal to ensure timezone shift for the slots is accurate

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't performed a self-review of my own code and corrected any misspellings
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my PR needs changes to the documentation
  • I haven't checked if my changes generate no new warnings
  • I haven't added tests that prove my fix is effective or that my feature works
  • I haven't checked if new and existing unit tests pass locally with my changes

@vercel
Copy link

vercel bot commented Oct 19, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
cal ✅ Ready (Inspect) Visit Preview Oct 19, 2022 at 11:15AM (UTC)

@alishaz-polymath alishaz-polymath self-assigned this Oct 19, 2022
@alishaz-polymath alishaz-polymath added 🐛 bug Something isn't working ✨ feature New feature or request 🥇 High Priority labels Oct 19, 2022
Copy link
Member Author

@alishaz-polymath alishaz-polymath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self review added

Comment on lines 50 to 59
const buildUtcOffset = (minutes: number): string => {
const h =
minutes > 0
? "+" + (Math.floor(minutes / 60) < 10 ? "0" + Math.floor(minutes / 60) : Math.floor(minutes / 60))
: "-" +
(Math.ceil(minutes / 60) > -10 ? "0" + Math.ceil(minutes / 60) * -1 : Math.ceil(minutes / 60) * -1);
const m = minutes > 0 ? minutes % 60 : (minutes % 60) * -1;
const offset = `${h}:${m}`;
return offset;
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply takes in the offset in minutes and returns the offset in the format of +-hh:mm. This is done to satisfy the needs of our beloved ICAL parser to adjust the timezone of the event's start and end date and to avoid the GMT shift caused in the absence of vTimezone

Comment on lines +291 to +305
if (!vcalendar.getFirstSubcomponent("vtimezone") && tzid) {
const timezoneComp = new ICAL.Component("vtimezone");
timezoneComp.addPropertyWithValue("tzid", tzid);
const standard = new ICAL.Component("standard");
// get timezone offset
const tzoffsetfrom = buildUtcOffset(dayjs(event.startDate.toJSDate()).tz(tzid, true).utcOffset());
const tzoffsetto = buildUtcOffset(dayjs(event.endDate.toJSDate()).tz(tzid, true).utcOffset());
// set timezone offset
standard.addPropertyWithValue("tzoffsetfrom", tzoffsetfrom);
standard.addPropertyWithValue("tzoffsetto", tzoffsetto);
// provide a standard dtstart
standard.addPropertyWithValue("dtstart", "1601-01-01T00:00:00");
timezoneComp.addSubcomponent(standard);
vcalendar.addSubcomponent(timezoneComp);
}
Copy link
Member Author

@alishaz-polymath alishaz-polymath Oct 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If vTimezone is absent and tzid is present, we "build" the vTimezone component from the tzid and make sure to include the dtstart, tzoffsetfrom, and tzoffsetto in the subcomponent standard and then add it to the vCalendar component to ensure proper timezone conversion

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might still require consideration of daylight savings but I believe I'd need to add that as a follow up

standard.addPropertyWithValue("tzoffsetfrom", tzoffsetfrom);
standard.addPropertyWithValue("tzoffsetto", tzoffsetto);
// provide a standard dtstart
standard.addPropertyWithValue("dtstart", "1601-01-01T00:00:00");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you get to 1601?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I just monitored a few calls and this seemed like a standard dtstart. It doesn't really matter as long as it is before the earliest start time of the calendar.

packages/lib/CalendarService.ts Outdated Show resolved Hide resolved
Co-authored-by: Alex van Andel <me@alexvanandel.com>
@alishaz-polymath alishaz-polymath added ♻️ autoupdate tells kodiak to keep this branch up-to-date automerge labels Oct 19, 2022
@kodiakhq kodiakhq bot merged commit 51e08a7 into main Oct 19, 2022
@kodiakhq kodiakhq bot deleted the fix/caldav-icalendar branch October 19, 2022 11:18
standard.addPropertyWithValue("dtstart", "1601-01-01T00:00:00");
timezoneComp.addSubcomponent(standard);
vcalendar.addSubcomponent(timezoneComp);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know what sorcery is going on in this PR @alishaz-polymath @emrysal 😂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pleasing the Timezone Masters 🥲

@davidwuest
Copy link

Still having the issue with iCalendar timezone. Running on Docker, the commits are already in the latest as far as I can see. Anyone els can confirm this?

@alishaz-polymath
Copy link
Member Author

Hey @davidwuest can you elaborate on the exact issue? There is still daylight issue to be taken care of so if you’re testing it post October dates, there will still be a discrepancy of 1 hour. If you’re testing in October, and with our latest main pull, please let me know.

@davidwuest
Copy link

@alishaz-polymath I was only testing within October. Checked that the latest main pull was in the docker build. I will make another build, without any cache to see if that is the issue. Let me know what I can do to support to fix this issue.

@alishaz-polymath
Copy link
Member Author

Can you please book me here and we can then take care of it on a call, explore it further

@PeerRich PeerRich added the core area: core, team members only label Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge ♻️ autoupdate tells kodiak to keep this branch up-to-date 🐛 bug Something isn't working core area: core, team members only ✨ feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apple Calendar/CalDav events are getting converted to GMT
5 participants