diff --git a/lib/event.js b/lib/event.js index a6a8e8b..d1ebaeb 100644 --- a/lib/event.js +++ b/lib/event.js @@ -61,12 +61,23 @@ VEvent.prototype.setDescription = function(desc) { this.addProperty('DESCRIPTION', desc); } -VEvent.prototype.setDate = function(start, end) { - this.addProperty('DTSTART', start); - if(end instanceof Date) - this.addProperty('DTEND', end); - else +VEvent.prototype.setDate = function(start, end, fullday) { + var startProperty = this.addProperty('DTSTART', start); + if (fullday) { + startProperty.setParameter('VALUE', 'DATE'); + startProperty.type = 'DATE'; + } + + if(end instanceof Date) { + var endProperty = this.addProperty('DTEND', end); + if (fullday) { + endProperty.setParameter('VALUE', 'DATE'); + endProperty.type = 'DATE'; + } + } + else { this.addProperty('DURATION', end); + } } VEvent.prototype.rrule = function() { diff --git a/spec/icalendar-spec.js b/spec/icalendar-spec.js index 6399822..0918c18 100644 --- a/spec/icalendar-spec.js +++ b/spec/icalendar-spec.js @@ -78,6 +78,27 @@ describe("iCalendar", function() { 'END:VCALENDAR\r\n', vevent.toString()); }); + it('Outputs full day VEvents correctly if setDate is used', function() { + // VEvent objects need to get a calendar wrapper... + var vevent = new icalendar.VEvent('testuid@daybilling.com'); + vevent.setDate(new Date(Date.UTC(2011,10,12,00,00,00)), + new Date(Date.UTC(2011,10,13,00,00,00)), true); + + var dtstamp = icalendar.format_value('DATE-TIME', vevent.getPropertyValue('DTSTAMP')); + + assert.equal( + 'BEGIN:VCALENDAR\r\n'+ + 'VERSION:2.0\r\n'+ + 'PRODID:'+icalendar.PRODID+'\r\n'+ + 'BEGIN:VEVENT\r\n'+ + 'DTSTAMP:'+dtstamp+'\r\n'+ + 'UID:testuid@daybilling.com\r\n'+ + 'DTSTART;VALUE=DATE:20111112\r\n'+ + 'DTEND;VALUE=DATE:20111113\r\n'+ + 'END:VEVENT\r\n'+ + 'END:VCALENDAR\r\n', vevent.toString()); + }); + it('wraps long lines correctly', function() { var vevent = new icalendar.VEvent('testuid@daybilling.com'); vevent.setDate(new Date(Date.UTC(2011,11,2,16,59,00)), 3600);