question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timezone not set correctly when iterating occurrences

See original GitHub issue

ics file:

BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
CREATED:20160728T114557Z
LAST-MODIFIED:20160728T122120Z
DTSTAMP:20160728T122120Z
UID:9fda684c-373b-4f58-9fc7-6db9f06218b5
SUMMARY:Test-Event
RRULE:FREQ=WEEKLY;UNTIL=20160912T080000Z
EXDATE:20160808T080000Z
DTSTART;TZID=Europe/Berlin:20160725T100000
DTEND;TZID=Europe/Berlin:20160725T110000
TRANSP:OPAQUE
SEQUENCE:3
X-MOZ-GENERATION:4
END:VEVENT
BEGIN:VEVENT
CREATED:20160728T115039Z
LAST-MODIFIED:20160728T115048Z
DTSTAMP:20160728T115048Z
UID:9fda684c-373b-4f58-9fc7-6db9f06218b5
SUMMARY:Test-Event - Reccurence #2
RECURRENCE-ID;TZID=Europe/Berlin:20160801T100000
DTSTART;TZID=Europe/Berlin:20160801T100000
DTEND;TZID=Europe/Berlin:20160801T110000
TRANSP:OPAQUE
SEQUENCE:2
X-MOZ-GENERATION:3
END:VEVENT
BEGIN:VEVENT
CREATED:20160728T114921Z
LAST-MODIFIED:20160728T122231Z
DTSTAMP:20160728T122231Z
UID:9fda684c-373b-4f58-9fc7-6db9f06218b5
SUMMARY:Test-Event
TRANSP:OPAQUE
CLASS:PUBLIC
RECURRENCE-ID;TZID=Europe/Berlin:20160725T100000
DTSTART;TZID=Europe/Berlin:20160725T100000
DTEND;TZID=Europe/Berlin:20160725T113000
END:VEVENT
PRODID:-//Inf-IT//InfCloud 0.12.1//EN
END:VCALENDAR

Code:

const ICAL = require("ical.js");
const fs = require('fs');

var buffer = fs.readFileSync("/file.ics", "utf8");
var jcal = ICAL.parse(buffer);
var vcalendar = new ICAL.Component(jcal);
var vevents = vcalendar.getAllSubcomponents('vevent');
var event;
var exceptions = [];
vevents.forEach((vevent, i) => {
  let _event = new ICAL.Event(vevent);
  if ( _event.isRecurring() ) {
    event = _event;
  } else if( _event.isRecurrenceException() ) {
    exceptions.push(_event);
  }
});

if(event) {
  exceptions.forEach((ex) => {
    event.relateException(ex);
  });

  var exdates = [];
  event.component.getAllProperties('exdate').forEach((exdate) => {
    exdates.push(exdate.getFirstValue().toJSDate());
  });

  let it = event.iterator();

  // console.log(it);

  var occ;
  while((occ = it.next())) {
    var details = event.getOccurrenceDetails(occ);
    var jsDate = details.startDate.toJSDate();
    // console.log(jsDate, exdates.indexOf(jsDate));
    /// Does not work due to different objects
    // Another problem is the timezone
    if(exdates.indexOf(jsDate) != -1) {
      console.log("    ", jsDate, 'IGNORED'); // THIS NEVER GETS CALLED
    } else {
      console.log("    ", jsDate, details.item.summary, event.findRangeException(details.startDate), it.exDate);
    }
  }
}

it.exDate is undefined after the date that should be excluded, but I still see it through the iterator.

In lib/ical/recur_expansion.js:267 you compare the EXDATE to “last”. Last points at the end of the event (10am), but the EXDATE points to the start (8am).

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
roberthartungcommented, Aug 1, 2016

Addition: It looks like a problem with the timezone. The exDate is correctly in timezone ‘Z’ with utcOffset 0. In contrast, the startDate I get from the iterator for the occurence details object is 10:00:00 with utcOffset 0 and tz ‘floating’ which is obviously wrong!

1reaction
mificommented, Mar 30, 2017

I made a wrapper for ical.js that solves this problem: https://github.com/mifi/ical-expander

Read more comments on GitHub >

github_iconTop Results From Across the Web

Timezone not set correctly when iterating occurrences #257
Timezone not set correctly when iterating occurrences #257 ... It seems that EXDATE is not considered in ical.js at all, I was not...
Read more >
TimeZones in Java - Stack Overflow
I am allowing users on my web app to schedule events based on time zones of their choice. I want ...
Read more >
There's a time zone bug in iOS and iPadOS. Here's what to do ...
It can cause alarms, calendar events, and other reminders to be missed because of the time discrepancy. 'Set Automatically' Resetting. Of course ...
Read more >
8 Time Zone Settings in the JRE
This chapter describes some issues that can arise with time zone settings with the Java Runtime Environment (JRE) on the Windows operating system....
Read more >
Managing Multiple Timezones for Events in Drupal
One way to simplify the process is to remove timezone names/abbreviations from both the display and the editor. The user viewing the event...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found