javascriptnode.jsicalendar

NodeJS problem with recurring events from ICal


I'm using this https://www.npmjs.com/package/ical node module to parse an ICal file to a JavaScript object. So now I want to have a function that gives me all events for the current week. My problem is, that there are recurring events. I've not found a property that helps me to identify when the recurring range starts and ends. How to process this ICal recurring events?


Solution

  • There's rrule package, you can create recurring events with it:

    const rule = new RRule({
      freq: RRule.WEEKLY,
      interval: 5,
      byweekday: [RRule.MO, RRule.FR],
      dtstart: new Date(Date.UTC(2012, 1, 1, 10, 30)),
      until: new Date(Date.UTC(2012, 12, 31))
    })
    

    or even parse a recurrence rule string:

    rrulestr('DTSTART:20120201T023000Z\nRRULE:FREQ=MONTHLY;COUNT=5')
    

    It has many other helper functions too such as between, before, all, etc.