From 8a7f0541fa3a324c1e9461bab3154b66cbae6a48 Mon Sep 17 00:00:00 2001 From: Michael Sealand Date: Tue, 11 Sep 2012 14:13:04 -0700 Subject: [PATCH] Add support for all day events Add support for altType in CalendarProperty. This way we can use two different types for DTSTART (DATE-TIME and DATE). When setDate() is called with an undefined end parameter, add the DTSTART property using its altType and do not add a DTEND or DURATION property. --- lib/base.js | 10 +++++----- lib/event.js | 13 ++++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/base.js b/lib/base.js index 663de9d..a1bc10f 100644 --- a/lib/base.js +++ b/lib/base.js @@ -49,7 +49,7 @@ var properties = exports.properties = { COMPLETED: { type: 'DATE-TIME' }, DTEND: { type: 'DATE-TIME' }, DUE: { type: 'DATE-TIME' }, - DTSTART: { type: 'DATE-TIME' }, + DTSTART: { type: 'DATE-TIME', altType: 'DATE' }, DURATION: { type: 'DURATION' }, FREEBUSY: { type: 'PERIOD' }, TRANSP: { type: 'TEXT' }, @@ -130,10 +130,10 @@ CalendarObject.prototype.addProperties = function(props) { props.forEach(this.addProperty.bind(this)); } -CalendarObject.prototype.addProperty = function(prop, value, parameters) { +CalendarObject.prototype.addProperty = function(prop, value, parameters, useAltType) { if(!(prop instanceof CalendarProperty)) { if(value === undefined) return; - prop = new CalendarProperty(prop, value, parameters); + prop = new CalendarProperty(prop, value, parameters, useAltType); } else prop = prop.clone(); @@ -240,10 +240,10 @@ CalendarObject.prototype.format = function() { -var CalendarProperty = exports.CalendarProperty = function(name, value, parameters) { +var CalendarProperty = exports.CalendarProperty = function(name, value, parameters, useAltType) { var propdef = properties[name]; - this.type = propdef && propdef.type ? propdef.type : 'TEXT'; + this.type = propdef && propdef[useAltType ? 'altType' : 'type'] ? propdef[useAltType ? 'altType' : 'type'] : 'TEXT'; this.name = name; this.value = value; this.parameters = parameters || {}; diff --git a/lib/event.js b/lib/event.js index 656323a..411aebc 100644 --- a/lib/event.js +++ b/lib/event.js @@ -59,11 +59,14 @@ VEvent.prototype.setDescription = function(desc) { } VEvent.prototype.setDate = function(start, end) { - this.addProperty('DTSTART', start); - if(end instanceof Date) - this.addProperty('DTEND', end); - else - this.addProperty('DURATION', end); + var allDay = (typeof end === 'undefined'); + this.addProperty('DTSTART', start, {}, allDay); + if(!allDay) { + if(end instanceof Date) + this.addProperty('DTEND', end); + else + this.addProperty('DURATION', end); + } } VEvent.prototype.rrule = function() {