ical-parser icon indicating copy to clipboard operation
ical-parser copied to clipboard

Dates with TZID incorrectly parsed with locale

Open RideLikeTheWind opened this issue 2 years ago • 2 comments

I have been reading an ICS file from a system we use and some dates that come in are pre-set in current (locale) time. They have the TZID param. In the code, index.js line 63ish you check the parameter:

if(params["TZID"] !== undefined) { ...

Which is ok, but the time returns incorrectly. I had to add this:

if(params["TZID"].search(/\//) != -1){ params["TZID"] = params["TZID"].slice(1); } events[event_count][k].value.toLocaleString(undefined, {timeZone: params["TZID"]});

which reduces the time by the timezone appropriately.

RideLikeTheWind avatar Feb 22 '23 07:02 RideLikeTheWind

I'm not 100% sure I understand the issue but if you think this would help others feel free to make a PR and we can get it added in.

Christop406 avatar Feb 22 '23 16:02 Christop406

Ok - I'll see how it goes in production first.

The issue is that some dates are like this:

DTSTART;TZID=/Australia/Sydney:20230130T070000

The original code simply appends 'Z', which assumes the date/time has not already compensated for the timezone. It is therefore necessary to strip the preceding "/" and then after parsing the time, applying the timezone shift appropriately so it can be displayed.

Note this works for Angular 13^ - it might be different elsewhere.

I'll initiate a pull request if testing works out ok.

RideLikeTheWind avatar Feb 23 '23 05:02 RideLikeTheWind