ical.js icon indicating copy to clipboard operation
ical.js copied to clipboard

Determine if event is all day or not.

Open nikmartin opened this issue 7 years ago • 4 comments

I can't find anything in the RFC about all day events, but both Outlook and Google are able to determine if an event is all day. Looking at an ics file with all day events, when the DTSTART and DTEND are both in this format:

DTSTART;VALUE=DATE:20180316
DTEND;VALUE=DATE:20180317

the event is 'All Day'

and if the DTSTART/END are either:

DTSTART:20180119T173000Z
DTEND:20180119T182000Z

or

DTSTART;TZID="(UTC-06:00) Central Time (US & Canada)":20180630T080000
DTEND;TZID="(UTC-06:00) Central Time (US & Canada)":20180630T083000

The event is not all day. Does ical.js give a higher order method to detect all day events? Is it just a matter of checking that start and end are exactly 24 hours apart, and are at midnight exactly?

nikmartin avatar Jan 18 '18 04:01 nikmartin

Hi Nik. An event is all-day if it has a VALUE=DATE, that should be a sufficient check. You could also assert that start date < end date, because a one day all day event has dtstart today, and dtend tomorrow. I haven’t checked, but possibly there is a helper in ICAL.Event

kewisch avatar Jan 18 '18 11:01 kewisch

Checking event.startDate.isDate is probably what you are looking for.

marcoancona avatar Jan 18 '18 13:01 marcoancona

I was thinking of a property in http://mozilla-comm.github.io/ical.js/api/ICAL.Event.html but it seems there are none. I'd take a patch to add a property allDay that checks to see that start and end date have isDate set. ICAL.Event isn't as widely used so it might be a bit lacking.

kewisch avatar Jan 18 '18 17:01 kewisch

@marcoancona I discovered this while prodding the ICAL.Event structure of an all day event on calendars exported from Outlook and Google : isDate is true on all day events, and false on events with start and end times, so that seems to be a good enough check until some boundary case pops up. I checked a single all day event, a multi-day event that has start and end times, with full days in between, and multi-day all day events, and it worked properly.

@kewisch good idea, I'll submit a patch and reference this issue if you want to mark this an enhancement

nikmartin avatar Jan 18 '18 19:01 nikmartin