ical-parser
ical-parser copied to clipboard
Dates with TZID incorrectly parsed with locale
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.
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.
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.