Getting UTC timestamps of iCal with Timezone using the mozilla-comm/ical.js lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Please note I'm also using underscore each function for the iterations | |
//iCal -> jsCal | |
var icalEvents = ICal.parse(iCalStringData); | |
//jsCal->Component | |
var comp = new Component(icalEvents[1]); | |
//Get all VTIMEZONE iCalendar components | |
var vtimezones = comp.getAllSubcomponents("vtimezone"); | |
//Add all timezones in iCalendar object to TimezonService | |
//if they are not already registered. | |
_.each(vtimezones, function (vtimezone) { | |
if (!(ICAL.TimezoneService.has( | |
vtimezone.getFirstPropertyValue("tzid")))) { | |
ICAL.TimezoneService.register(vtimezone); | |
} | |
}); | |
//Get all VEVENT iCalendar components | |
var vevents = comp.getAllSubcomponents("vevent"); | |
var events = []; | |
var eventCount = 1; | |
_.each(vevents, function (vevent) { | |
var event = new Event(vevent); | |
//Get the datetime info in UTC format with appropiate offset | |
var startDate = new Date(event.startDate.toUnixTime() * 1000); | |
var endDate = new Date(event.endDate.toUnixTime() * 1000); | |
console.log(eventCount, " - - - - - - - - - - - - - - - - - - "); | |
console.log("UID:", event.uid); | |
console.log("Recurrent?", event.isRecurring()); | |
console.log("Start:", startDate); | |
console.log("End:", endDate); | |
//This also depends on the correct timezone to be present in TimezoneService | |
console.log("Duration:",event.duration.toString()); | |
console.log("Lugar:", event.location); | |
console.log("Organizer:", event.organizer); | |
console.log("Atendees:", event.attendees); | |
console.log("Summary:", event.summary); | |
console.log("Description", event.description); | |
console.log("\n"); | |
events.push(event); | |
eventCount++; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment