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

Recurring events with exclusions are not handled

Open mcbethio opened this issue 1 year ago • 7 comments

With my ICS format of EXDATE;TZID=Europe/London:20241217T174500 EXDATE;TZID=Europe/London:20241224T174500

parseIcs ignores the exceptions and creates exdate: []

Is this intended?

mcbethio avatar Jan 31 '25 19:01 mcbethio

are you sure? if using console.log(...+event) then elements in the exdate:[] array are not good js objects, so when JSON.stringify() happens they dont get printed but if you use console.log(..., event) then they do!

sdetweil avatar May 22 '25 20:05 sdetweil

please change the console log to use

(events)

instead of JSON.stringify(events)

as stringify cannot process the exclude array

sdetweil avatar May 24 '25 20:05 sdetweil

Hi @sdetweil, and thank you for explaining that. I deleted my comment after understanding 💡 what you were saying in your previous comment.

This is an exceedingly weird implementation. In my 10+ years of Node.js development I have never seen this pattern.

I understand that you were not the one who did this — it comes from the https://github.com/peterbraden/ical.js library that you forked.

For my own future reference and anyone who makes it to this page:

The exdate array is being used as an object. (!!)

exdate: [ '2025-05-24': [Date] ]

This is an array that:

  • Has been assigned a property named '2025-05-24'
  • That property contains a Date object (shown as [Date] in the console output)

To access it you would do this:

const exceptionDate = events['47D3081A-3924-4C7C-9FB0-A980B92C639E'].exdate['2025-05-24'];

Also note that the length property of such an array is 0. To enumerate it, use Object.entries. Array methods will not work as expected.


My goal was to build a working calendar plugin for TRMNL, which seems to ignore exclusion dates on my calendar. Now I wonder if they are using this library (or the one that it was forked from).

I wonder how many products and services around the world have broken recurring date features because of this weird implementation?

This deserves a callout in the README. It probably can’t be fixed because of backward compatibility but maybe as a future direction a new more modern parser could be developed that returns a more standard data structure. Then users could choose to use the legacy parser or the modern one.

natesilva avatar May 24 '25 21:05 natesilva

my code in MagicMirror https://github.com/MagicMirrorOrg/MagicMirror/blob/master/modules/default/calendar/calendarfetcherutils.js

there can be more than one entry in exdate

does this

Image

sdetweil avatar May 24 '25 21:05 sdetweil

in js array IS an object

sdetweil avatar May 24 '25 21:05 sdetweil

Same problem as an earlier issue: https://github.com/jens-maus/node-ical/issues/167

runely avatar Dec 28 '25 23:12 runely

I've created a PR (#423) that addresses this issue by changing exdate from an array to a plain object. This fixes the JSON.stringify() and .length problems while keeping all existing usage patterns working.

I've added regression tests to prevent this from happening again. Would appreciate if you could review and let me know if I'm heading in the wrong direction! 🙂

KristjanESPERANTO avatar Dec 29 '25 20:12 KristjanESPERANTO