GAS-ICS-Sync icon indicating copy to clipboard operation
GAS-ICS-Sync copied to clipboard

DTSTART;TZID=UTC

Open Ali1 opened this issue 5 years ago • 6 comments

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!

Ali1 avatar Aug 10 '20 20:08 Ali1

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 avatar Aug 10 '20 20:08 Ali1

@Ali1 There are actually two separate issues with the calendar you posted.

  1. 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.
  2. The event has no UID property.

You can use this version of the script, it should work around both issues and sync without errors.

jonas0b1011001 avatar Sep 13 '20 10:09 jonas0b1011001

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.

Ali1 avatar Sep 18 '20 11:09 Ali1

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.

jonas0b1011001 avatar Sep 18 '20 12:09 jonas0b1011001

Spawned off #173 to add support for calendars without UID properties since we've seen this a couple times (albeit, rarely)

derekantrican avatar Dec 17 '20 03:12 derekantrican

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.

bjliu avatar May 15 '21 20:05 bjliu