Question

I am trying to parse the .ics file in my application. My application has server side java layer and client side javascript part to it. I am using ical4j library to parse it.

Problem is DTSTART of the event is not in UTC format sometimes. And whenever it is not in UTC .ics file has VTIMEZONE component which I am parsing and getting TZID property from it.

Java layer finally send JSON to client. In the above mentioned case DTSTART, DTEND and TZID are being sent in JSON.

Client has to convert DTSTART and DTEND to UTC using TZID. I tried with moment.js since i could not find any other api which can do this.

moment.tz("2014-02-06 05:30", "NorthAmerica/Eastern").format()

With moment.js below is the error I get,

TypeError: Cannot call method 'rule' of undefined

But below code works fine,

moment.tz("2014-02-06 17:30", "America/Toronto").format()

Is it not possible to use TZID as is (i.e NorthAmerica/Eastern) from .ics file? Also Is there any other way or JS library which can give me UTC with all timezones and also considering Observance?

Was it helpful?

Solution

you should be aware that the icalendar specification RFC5545 clearly states in the TZID, that:

This document does not define a naming convention for time zone identifiers. Implementers may want to use the naming conventions defined in existing time zone specifications such as the public-domain TZ database [TZDB]. The specification of globally unique time zone identifiers is not addressed by this document and is left for future study.

so clearly while America/Toronto is listed in Olsson database (see here), America/Eastern is not which explains why your JS library cannot recognize it.

For a robust design you would need to either convert on server side to UTC or to have an actual JS class capable to parse ICS VTIMEZONE component.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top