Skip to content
This repository was archived by the owner on Aug 15, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions lib/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
21 changes: 21 additions & 0 deletions spec/icalendar-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down