Search code examples
icalendar

What is the exact meaning of TZOFFSETFROM and TZOFFSETTO and how to calculate/use it?


I'm looking for a profound explanation what exactly the difference between TZOFFSETFROM and TZOFFSETTO in an iCalendar description is and how to calculate it.

While it is described here: https://www.rfc-editor.org/rfc/rfc5545#section-3.6.5 [Page 65] I can't wrap my head around the meaning and especially how to calculate it. I have a list of all timezones and their related UTC_offset_StandardTime and UTC_offset_DaylightSavingTime but there is no "…onset…"-time.

While there is a somehow answer https://stackoverflow.com/a/3872214 I can't find a resource which proves that this right.

What am I missing?


Solution

  • Re: "How to calculate the timezone offset":

    It is not 'calculated', but rather looked up - most systems have this information built in using the Olson timezone database, and kept (hopefully) up to date. The systems or languages usually have a function to get the offset for a given date and time. EG:

    Most systems maintain such a db. Usually there is a recurring rule that always is so, however countries and areas may change the date of daylight saving change. See https://en.wikipedia.org/wiki/Daylight_saving_time_in_Australia#Western_Australia and changes made for the Olympics. This would mean an extra set of VTIMEZONE DST transition definitions for those areas, with DTSTARTS and UNTIL's on any recurring rules to indicate over what years they apply or do not apply.

    Now the .ics specification says we must include these timezone transitions - the daylight saving changes in a VTIMEZONE definition in the file.

    That leads us to your other question:

    RE: what is TZOFFSETFROM and TZOFFSETTO?

    They are literally for each transition date generated by the RRULE (or just a date if not recurring if it was a one-off), relative to UTC or GMT:

    • the OFFSET FROM which a daylight saving change is coming and
    • the OFFSET TO which a daylight saving change is going

    Take the New York 2021 daylight savings change on 14 March. The timezone offset is -5. After 14 march 2021 2 am, the timezoneoffset will be -4. See https://www.timeanddate.com/time/zone/usa/new-york-state.

    So If we look at what google calendar outputs, we see that on the second sunday of march at 2am, Daylight saving begins, NY goes

    • FROM -05 and
    • TO -04.

    Then when they revert to Standard Time on the 1st sunday in November, NY goes

    • FROM an offset of -04 and
    • TO an offset of -05.

    NOTE that both (a FROM and a TO offset) are required because the change is NOT always by an hour. Sometimes the change may be 30 minutes. See https://www.timeanddate.com/time/time-zones-interesting.html and scroll down near the bottom. You'll see Lord Howe Island had a 1/2 hour change and further down under 'Historic half hour offsets' what North Korea did in 2015 and Venezuela in 2016.

    Google Calendar New York example:

    BEGIN:VTIMEZONE
    TZID:America/New_York
    X-LIC-LOCATION:America/New_York
    BEGIN:DAYLIGHT
    TZOFFSETFROM:-0500
    TZOFFSETTO:-0400
    TZNAME:EDT
    DTSTART:19700308T020000
    RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
    END:DAYLIGHT
    BEGIN:STANDARD
    TZOFFSETFROM:-0400
    TZOFFSETTO:-0500
    TZNAME:EST
    DTSTART:19701101T020000
    RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
    END:STANDARD
    END:VTIMEZONE