GAS-ICS-Sync
GAS-ICS-Sync copied to clipboard
DTSTART;TZID=UTC
Hi!
I'm trying to sync with an ICS feed with these contents:
BEGIN:VCALENDAR
VERSION:2.0
TIMEZONE:UTC
BEGIN:VEVENT
SUMMARY:abc
DTSTART;TZID=UTC;VALUE=DATE-TIME:20200812T140000Z
DTEND;TZID=UTC;VALUE=DATE-TIME:20200812T190000Z
DTSTAMP;VALUE=DATE-TIME:20200810T141030Z
DESCRIPTION:def
END:VEVENT
END:VCALENDAR
Syncing results in this error:
TypeError: Cannot read property 'parent' of null
at addSubcomponent(ical.js:2562:21)
at updateTimezones(ical.js:97:14)
at parseResponses(Helpers:115:18)
at startSync(Code:167:17)REFRESH
Removing the TZID=UTC from the DTSTART and DTEND attributes fixes the problem.
DTSTART;VALUE=DATE-TIME:20200812T140000Z
DTEND;VALUE=DATE-TIME:20200812T190000Z
Is there scope to support this or is it just completely invalid ICS?
Thanks!
Just to add the ics file is accepted by Google Calendar and Outlook, so ideally shouldn't cause problems for this app. Thank you.
@Ali1 There are actually two separate issues with the calendar you posted.
- As dtstart and dtend are referencing TZID=UTC, ical.js is looking for a vtimezone-component that defines the UTC-Timezone. As it is not present in the Calendar it throws the error you posted.
- The event has no UID property.
You can use this version of the script, it should work around both issues and sync without errors.
Many thanks. Is this version an alternative script or is it something that will be built in to the core code in the future? I've found a work-around by just having a PHP script edit the ics and remove that "TZID=UTC" for now, I can wait for a stable version.
<?php
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=calendar.ics');
$ics = file_get_contents('ICS URL);
//$ics = str_replace("BEGIN:VCALENDAR", "BEGIN:VCALENDAR\r\nTIMEZONE:UTC", $ics);
$ics = preg_replace('/^DT(START|END)[:;]TZID=UTC[:;](.*)(Z)?$/im', 'DT$1:$2Z', $ics);
echo $ics;
It's strange, because 2 different services where you can have ICS export of your calendar had this similar issue and both actually work with most calendar clients just fine. I think it might be a common ics error because most clients find a way around it, perpetuating the issue.
This is the same script adjusted to work around the issues with the file you are trying to sync. You should be fine using that version without the additional php script.
According to RFC 5545
The "TZID" property parameter MUST NOT be applied to DATE properties and DATE-TIME or TIME properties whose time values are specified in UTC.
Most of the parsing is done by ical.is which is very picky with nonstandard inputs. It's a thin line between accepting common errors and adding an exception for basically anything that could be wrong.
Spawned off #173 to add support for calendars without UID properties since we've seen this a couple times (albeit, rarely)
If you don't need UTC you can change the lines in ical.js.gs from
if (
reqTzid.hasOwnProperty(i) &&
!vtimezones[i] &&
ICAL.TimezoneService.has(i)
)
to
if (
reqTzid.hasOwnProperty(i) &&
!vtimezones[i] &&
ICAL.TimezoneService.has(i) &&
i != "UTC"
)
as a temporary fix (I'm just a casual user of the script).
The issue is that ICAL.TimezoneService.get("UTC").component will return null.