Closed Meekohi closed 8 years ago
This worked for me. Would be nice to have a simplified example like this in the README or documentation along with whatever caveats are needed (handling recurring events, etc):
var url = "https://calendar.google.com/calendar/ical/"+email+"/public/basic.ics";
request(url,function(err, resp, calendarData){
var jcal = icaljs.parse(calendarData);
var vcal = new icaljs.Component(jcal);
var vevents = vcal.getAllSubcomponents("vevent");
return _.map(vevents,function(vevent){
return {
name: vevent.getFirstPropertyValue("summary"),
starttime: moment(vevent.getFirstPropertyValue("dtstart")).format(),
endtime: moment(vevent.getFirstPropertyValue("dtend")).format(),
description: vevent.getFirstPropertyValue("description")
};
});
});
How about this page? https://github.com/mozilla-comm/ical.js/wiki/Parsing-basic-iCalendar
I noticed that moment(vevent.getFirstPropertyValue("dtstart")).format()
was dropping the hours, minutes and seconds in the solution from @Meekohi. Adding .toString()
to the icaltime components solves this problem.
...
starttime: moment(vevent.getFirstPropertyValue("dtstart").toString()).format(),
endtime: moment(vevent.getFirstPropertyValue("dtend").toString()).format(),
...
So... can I use this library to get a list of all the events for a month in an
.ics
file? Any example code?