/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml */ dojo.provide("dojo.cal.iCalendar"); dojo.require("dojo.lang.common"); dojo.require("dojo.cal.textDirectory"); dojo.require("dojo.date.common"); dojo.require("dojo.date.serialize"); dojo.cal.iCalendar.fromText = function (/* string */text) { // summary // Parse text of an iCalendar and return an array of iCalendar objects var properties = dojo.cal.textDirectory.tokenise(text); var calendars = []; //dojo.debug("Parsing iCal String"); for (var i = 0, begun = false; i < properties.length; i++) { var prop = properties[i]; if (!begun) { if (prop.name == 'BEGIN' && prop.value == 'VCALENDAR') { begun = true; var calbody = []; } } else if (prop.name == 'END' && prop.value == 'VCALENDAR') { calendars.push(new dojo.cal.iCalendar.VCalendar(calbody)); begun = false; } else { calbody.push(prop); } } return /* array */calendars; } dojo.cal.iCalendar.Component = function (/* string */ body ) { // summary // A component is the basic container of all this stuff. if (!this.name) { this.name = "COMPONENT" } this.properties = []; this.components = []; if (body) { for (var i = 0, context = ''; i < body.length; i++) { if (context == '') { if (body[i].name == 'BEGIN') { context = body[i].value; var childprops = []; } else { this.addProperty(new dojo.cal.iCalendar.Property(body[i])); } } else if (body[i].name == 'END' && body[i].value == context) { if (context=="VEVENT") { this.addComponent(new dojo.cal.iCalendar.VEvent(childprops)); } else if (context=="VTIMEZONE") { this.addComponent(new dojo.cal.iCalendar.VTimeZone(childprops)); } else if (context=="VTODO") { this.addComponent(new dojo.cal.iCalendar.VTodo(childprops)); } else if (context=="VJOURNAL") { this.addComponent(new dojo.cal.iCalendar.VJournal(childprops)); } else if (context=="VFREEBUSY") { this.addComponent(new dojo.cal.iCalendar.VFreeBusy(childprops)); } else if (context=="STANDARD") { this.addComponent(new dojo.cal.iCalendar.Standard(childprops)); } else if (context=="DAYLIGHT") { this.addComponent(new dojo.cal.iCalendar.Daylight(childprops)); } else if (context=="VALARM") { this.addComponent(new dojo.cal.iCalendar.VAlarm(childprops)); }else { dojo.unimplemented("dojo.cal.iCalendar." + context); } context = ''; } else { childprops.push(body[i]); } } if (this._ValidProperties) { this.postCreate(); } } } dojo.extend(dojo.cal.iCalendar.Component, { addProperty: function (prop) { // summary // push a new property onto a component. this.properties.push(prop); this[prop.name.toLowerCase()] = prop; }, addComponent: function (prop) { // summary // add a component to this components list of children. this.components.push(prop); }, postCreate: function() { for (var x=0; x 0) { return events; } return null; } }); /* * STANDARD */ var StandardProperties = [ _P("dtstart", 1, true), _P("tzoffsetto", 1, true), _P("tzoffsetfrom", 1, true), _P("comment"), _P("rdate"), _P("rrule"), _P("tzname") ]; dojo.cal.iCalendar.Standard = function (/* string */ body) { // summary // STANDARD Component this.name = "STANDARD"; this._ValidProperties = StandardProperties; dojo.cal.iCalendar.Component.call(this, body); } dojo.inherits(dojo.cal.iCalendar.Standard, dojo.cal.iCalendar.Component); /* * DAYLIGHT */ var DaylightProperties = [ _P("dtstart", 1, true), _P("tzoffsetto", 1, true), _P("tzoffsetfrom", 1, true), _P("comment"), _P("rdate"), _P("rrule"), _P("tzname") ]; dojo.cal.iCalendar.Daylight = function (/* string */ body) { // summary // Daylight Component this.name = "DAYLIGHT"; this._ValidProperties = DaylightProperties; dojo.cal.iCalendar.Component.call(this, body); } dojo.inherits(dojo.cal.iCalendar.Daylight, dojo.cal.iCalendar.Component); /* * VEVENT */ var VEventProperties = [ // these can occur once only _P("class", 1), _P("created", 1), _P("description", 1), _P("dtstart", 1), _P("geo", 1), _P("last-mod", 1), _P("location", 1), _P("organizer", 1), _P("priority", 1), _P("dtstamp", 1), _P("seq", 1), _P("status", 1), _P("summary", 1), _P("transp", 1), _P("uid", 1), _P("url", 1), _P("recurid", 1), // these two are exclusive [_P("dtend", 1), _P("duration", 1)], // these can occur many times over _P("attach"), _P("attendee"), _P("categories"), _P("comment"), _P("contact"), _P("exdate"), _P("exrule"), _P("rstatus"), _P("related"), _P("resources"), _P("rdate"), _P("rrule") ]; dojo.cal.iCalendar.VEvent = function (/* string */ body) { // summary // VEVENT Component this._ValidProperties = VEventProperties; this.name = "VEVENT"; dojo.cal.iCalendar.Component.call(this, body); this.recurring = false; this.startDate = dojo.date.fromIso8601(this.dtstart.value); } dojo.inherits(dojo.cal.iCalendar.VEvent, dojo.cal.iCalendar.Component); dojo.extend(dojo.cal.iCalendar.VEvent, { getDates: function(until) { var dtstart = this.getDate(); var recurranceSet = []; var weekdays=["su","mo","tu","we","th","fr","sa"]; var order = { "daily": 1, "weekly": 2, "monthly": 3, "yearly": 4, "byday": 1, "bymonthday": 1, "byweekno": 2, "bymonth": 3, "byyearday": 4}; // expand rrules into the recurrance for (var x=0; x interval) { interval = rrule.interval; } var set = []; var freqInt = order[freq]; if (rrule.until) { var tmpUntil = dojo.date.fromIso8601(rrule.until); } else { var tmpUntil = until } if (tmpUntil > until) { tmpUntil = until } if (dtstart 1) { var regex = "([+-]?)([0-9]{1,3})"; for (var z=1; x 0) { var regex = "([+-]?)([0-9]{1,3})"; for (var z=0; z 0) { var regex = "([+-]?)([0-9]{0,1}?)([A-Za-z]{1,2})"; for (var z=0; z