Skip to content

Timezone support #3

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

Open
gajus opened this issue Mar 16, 2020 · 1 comment
Open

Timezone support #3

gajus opened this issue Mar 16, 2020 · 1 comment

Comments

@gajus
Copy link

gajus commented Mar 16, 2020

Is setting a timezone not supported?

@erkstruwe
Copy link

erkstruwe commented Dec 8, 2022

After having implemented a lot of functionality in my application based on this repo I found out today that something like

DTSTART;TZID=/Europe/Berlin:20221029T080000
RRULE:FREQ=DAILY;UNTIL=20221031T080000

is actually not supported by this repo.

This is usually needed to cater for daylight saving in a particular time zone. In this case, you would expect occurrences to always be at 8AM German Time. This, however, corresponds to 6AM UTC on Oct 29th 2022, but 7AM UTC on Oct 30th 2022. Thus, interpreting times as UTC does not work here.

However, after playing and reading around quite a bit I came up with a solution that worked for me:
Consider datetimes in the database as "floating" instead of UTC and do not store any time zone information in it. "Floating" time zones are actually a thing (https://icalendar.org/CalDAV-Access-RFC-4791/7-3-date-and-floating-time.html).

"_rrule"."occurrences" for the ruleset

DTSTART:20221029T080000
RRULE:FREQ=DAILY;UNTIL=20221031T080000

yields this result in my JavaScript application code:

2022-10-29T08:00:00.000Z
2022-10-30T08:00:00.000Z
2022-10-31T08:00:00.000Z

Leveraging the parseFromTimeZone function from date-fns we can adjust them for time zone and daylight savings at the same time, though, and get the expected results:

parseFromTimeZone(occurrence.toISOString().slice(0, -1), { timeZone: "Europe/Berlin" })
// 2022-10-29T06:00:00.000Z
// 2022-10-30T07:00:00.000Z
// 2022-10-31T07:00:00.000Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants