peterbraden / ical.js

ical for javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does not handle weird Google calendar timestamp + TZ combos

jayjanssen opened this issue · comments

I found that this module will not parse events that contain DTSTART or DTEND values that look like this:

DTSTART;TZID=America/Los_Angeles:20140505T183000

The events simply don't show up in the output.

@jayjanssen got a similar issue but then realized there are different kinds of events like VEVENT and VTIMEZONE that are returned by the lib. In my case, skipping VTIMEZONE events made the trick.

In case anyone is wondering, this fixes it, tidies things up, as well as stopping jsonhint complaining about the example code

'use strict';

const ical = require('ical');
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, function (err, data) {
	for (let k in data) {
		if (data.hasOwnProperty(k)) {
			var ev = data[k];
			if (data[k].type == 'VEVENT') {
				console.log(`${ev.summary} is in ${ev.location} on the ${ev.start.getDate()} of ${months[ev.start.getMonth()]} at ${ev.start.toLocaleTimeString('en-GB')}`);

			}
		}
	}
});