Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed all day events handling #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
43 changes: 28 additions & 15 deletions ics.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,16 @@ var ics = function(uidDomain, prodId) {
var end = end_year + end_month + end_day + end_time;
var now = now_year + now_month + now_day + now_time;

var calendarEvent = [
'BEGIN:VEVENT',
'UID:' + calendarEvents.length + "@" + uidDomain,
'CLASS:PUBLIC',
'DESCRIPTION:' + description
];

// recurrence rrule vars
var rruleString;
if (rrule) {
var rruleString;
if (rrule.rrule) {
rruleString = rrule.rrule;
} else {
Expand All @@ -170,27 +177,33 @@ var ics = function(uidDomain, prodId) {
rruleString += ';BYDAY=' + rrule.byday.join(',');
}
}

calendarEvent.push(rruleString);
}

var stamp = new Date().toISOString();
calendarEvent.push('DTSTAMP;VALUE=DATE-TIME:' + now);

var calendarEvent = [
'BEGIN:VEVENT',
'UID:' + calendarEvents.length + "@" + uidDomain,
'CLASS:PUBLIC',
'DESCRIPTION:' + description,
'DTSTAMP;VALUE=DATE-TIME:' + now,
'DTSTART;VALUE=DATE-TIME:' + start,
'DTEND;VALUE=DATE-TIME:' + end,
if (start_time !== '') {
calendarEvent.push('DTSTART;VALUE=DATE-TIME:' + start);
} else {
calendarEvent.push('DTSTART;VALUE=DATE:' + start);
}

// If start and end refer to the same day without time,
// it's a one day event, and no DTEND is needed.
// https://stackoverflow.com/a/30249034
if (end_time !== '') {
calendarEvent.push('DTEND;VALUE=DATE-TIME:' + end);
} else if (end !== start) {
calendarEvent.push('DTEND;VALUE=DATE:' + end);
}

calendarEvent.push(
'LOCATION:' + location,
'SUMMARY;LANGUAGE=en-us:' + subject,
'TRANSP:TRANSPARENT',
'END:VEVENT'
];

if (rruleString) {
calendarEvent.splice(4, 0, rruleString);
}
);

calendarEvent = calendarEvent.join(SEPARATOR);

Expand Down