Merging bugfix

This commit is contained in:
Travis Krause
2017-09-14 11:05:04 -05:00
6 changed files with 377 additions and 331 deletions
+11
View File
@@ -0,0 +1,11 @@
root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
# editorconfig-tools is unable to ignore longs strings or urls
max_line_length = null
+56 -50
View File
@@ -1,55 +1,61 @@
<!DOCTYPE html> <!DOCTYPE html>
<head> <head>
<script type="text/javascript" src="https://rawgithub.com/nwcell/ics.js/master/ics.deps.min.js"></script> <!-- <script type="text/javascript" src="https://rawgithub.com/nwcell/ics.js/master/ics.deps.min.js"></script> -->
<script type="text/javascript" src="https://rawgithub.com/nwcell/ics.js/master/demo/demo.js"></script>
<style> <!-- include source files here... -->
html, body { <script src="../bower_components/Blob.js/Blob.js"></script>
height: 100%; <script src="../bower_components/file-saver/FileSaver.js"></script>
width: 100%; <script src="../ics.js"></script>
} <script type="text/javascript" src="https://rawgithub.com/nwcell/ics.js/master/demo/demo.js"></script>
.wrap {
margin: auto; <style>
position: absolute; html, body {
top: 0; left: 0; bottom: 0; right: 0; height: 100%;
height: 50px; width: 100%;
width: 100px; }
} .wrap {
a { margin: auto;
margin-top: 5px; position: absolute;
margin-bottom: 5px; top: 0; left: 0; bottom: 0; right: 0;
display: inline-block; height: 50px;
padding: 6px 12px; width: 100px;
margin-bottom: 0; }
font-size: 14px; a {
font-weight: normal; margin-top: 5px;
line-height: 1.428571429; margin-bottom: 5px;
text-align: center; display: inline-block;
white-space: nowrap; padding: 6px 12px;
vertical-align: middle; margin-bottom: 0;
cursor: pointer; font-size: 14px;
border: 1px solid transparent; font-weight: normal;
border-radius: 4px; line-height: 1.428571429;
-webkit-user-select: none; text-align: center;
-moz-user-select: none; white-space: nowrap;
-ms-user-select: none; vertical-align: middle;
-o-user-select: none; cursor: pointer;
cursor: pointer; border: 1px solid transparent;
color: #ffffff; border-radius: 4px;
text-decoration: none; -webkit-user-select: none;
font-weight: bold; -moz-user-select: none;
background-color: #428bca; -ms-user-select: none;
border-color: #357ebd; -o-user-select: none;
font-family: sans-serif; cursor: pointer;
width: 120px; color: #ffffff;
} text-decoration: none;
</style> font-weight: bold;
background-color: #428bca;
border-color: #357ebd;
font-family: sans-serif;
width: 120px;
}
</style>
</head> </head>
<body> <body>
<div class="wrap"> <div class="wrap">
<a href="javascript:cal_single.download('Awesome Day')">Single Event</a> <a href="javascript:cal_single.download('Awesome Day')">Single Event</a>
<br> <br>
<a href="javascript:cal.download('Holidays')">Multiple Events</a> <a href="javascript:cal.download('Holidays')">Multiple Events</a>
<br> <br>
<a href="javascript:makelogs(cal)">Console Output</a> <a href="javascript:makelogs(cal)">Console Output</a>
</div> </div>
</html> </html>
+228 -200
View File
@@ -1,212 +1,240 @@
/* global saveAs, Blob, BlobBuilder, console */ /* global saveAs, Blob, BlobBuilder, console */
/* exported ics */ /* exported ics */
var ics = function() { var ics = function( uidDomain, prodId ) {
'use strict'; 'use strict';
if (navigator.userAgent.indexOf('MSIE') > -1 && navigator.userAgent.indexOf('MSIE 10') == -1) { if (navigator.userAgent.indexOf('MSIE') > -1 && navigator.userAgent.indexOf('MSIE 10') == -1) {
console.log('Unsupported Browser'); console.log('Unsupported Browser');
return; return;
} }
var SEPARATOR = (navigator.appVersion.indexOf('Win') !== -1) ? '\r\n' : '\n'; if (typeof uidDomain === 'undefined') { uidDomain = 'default'; }
var calendarEvents = []; if (typeof prodId === 'undefined') { prodId = 'Calendar'; }
var calendarStart = [
'BEGIN:VCALENDAR',
'VERSION:2.0'
].join(SEPARATOR);
var calendarEnd = SEPARATOR + 'END:VCALENDAR';
var BYDAY_VALUES = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'];
return { var SEPARATOR = (navigator.appVersion.indexOf('Win') !== -1) ? '\r\n' : '\n';
/** var calendarEvents = [];
* Returns events array var calendarStart = [
* @return {array} Events 'BEGIN:VCALENDAR',
*/ 'PRODID:'+prodId,
'events': function() { 'VERSION:2.0'
return calendarEvents; ].join(SEPARATOR);
}, var calendarEnd = SEPARATOR + 'END:VCALENDAR';
var BYDAY_VALUES = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'];
/** return {
* Returns calendar /**
* @return {string} Calendar in iCalendar format * Returns events array
*/ * @return {array} Events
'calendar': function() { */
return calendarStart + SEPARATOR + calendarEvents.join(SEPARATOR) + calendarEnd; 'events': function() {
}, return calendarEvents;
},
/** /**
* Add event to the calendar * Returns calendar
* @param {string} subject Subject/Title of event * @return {string} Calendar in iCalendar format
* @param {string} description Description of event */
* @param {string} location Location of event 'calendar': function() {
* @param {string} begin Beginning date of event return calendarStart + SEPARATOR + calendarEvents.join(SEPARATOR) + calendarEnd;
* @param {string} stop Ending date of event },
*/
'addEvent': function(subject, description, location, begin, stop, rrule) {
// I'm not in the mood to make these optional... So they are all required
if (typeof subject === 'undefined' ||
typeof description === 'undefined' ||
typeof location === 'undefined' ||
typeof begin === 'undefined' ||
typeof stop === 'undefined'
) {
return false;
}
// validate rrule /**
if (rrule) { * Add event to the calendar
if (!rrule.rule) { * @param {string} subject Subject/Title of event
if (rrule.freq !== 'YEARLY' && rrule.freq !== 'MONTHLY' && rrule.freq !== 'WEEKLY' && rrule.freq !== 'DAILY') { * @param {string} description Description of event
throw "Recurrence rule frequency must be provided and be one of the following: 'YEARLY', 'MONTHLY', 'WEEKLY', or 'DAILY'"; * @param {string} location Location of event
} * @param {string} begin Beginning date of event
* @param {string} stop Ending date of event
*/
'addEvent': function(subject, description, location, begin, stop, rrule) {
// I'm not in the mood to make these optional... So they are all required
if (typeof subject === 'undefined' ||
typeof description === 'undefined' ||
typeof location === 'undefined' ||
typeof begin === 'undefined' ||
typeof stop === 'undefined'
) {
return false;
}
if (rrule.until) { // validate rrule
if (isNaN(Date.parse(rrule.until))) { if (rrule) {
throw "Recurrence rule 'until' must be a valid date string"; if (!rrule.rule) {
} if (rrule.freq !== 'YEARLY' && rrule.freq !== 'MONTHLY' && rrule.freq !== 'WEEKLY' && rrule.freq !== 'DAILY') {
} throw "Recurrence rule frequency must be provided and be one of the following: 'YEARLY', 'MONTHLY', 'WEEKLY', or 'DAILY'";
if (rrule.interval) {
if (isNaN(parseInt(rrule.interval))) {
throw "Recurrence rule 'interval' must be an integer";
}
}
if (rrule.count) {
if (isNaN(parseInt(rrule.count))) {
throw "Recurrence rule 'count' must be an integer";
}
}
if (typeof rrule.byday !== 'undefined') {
if ( (Object.prototype.toString.call(rrule.byday) !== '[object Array]') ) {
throw "Recurrence rule 'byday' must be an array";
}
if (rrule.byday.length > 7) {
throw "Recurrence rule 'byday' array must not be longer than the 7 days in a week";
}
// Filter any possible repeats
rrule.byday = rrule.byday.filter(function(elem, pos) {
return rrule.byday.indexOf(elem) == pos;
});
for (var d in rrule.byday) {
if (BYDAY_VALUES.indexOf(rrule.byday[d]) < 0) {
throw "Recurrence rule 'byday' values must include only the following: 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'";
}
}
}
}
}
//TODO add time and time zone? use moment to format?
var start_date = new Date(begin);
var end_date = new Date(stop);
var start_year = ("0000" + (start_date.getFullYear().toString())).slice(-4);
var start_month = ("00" + ((start_date.getMonth() + 1).toString())).slice(-2);
var start_day = ("00" + ((start_date.getDate()).toString())).slice(-2);
var start_hours = ("00" + (start_date.getHours().toString())).slice(-2);
var start_minutes = ("00" + (start_date.getMinutes().toString())).slice(-2);
var start_seconds = ("00" + (start_date.getSeconds().toString())).slice(-2);
var end_year = ("0000" + (end_date.getFullYear().toString())).slice(-4);
var end_month = ("00" + ((end_date.getMonth() + 1).toString())).slice(-2);
var end_day = ("00" + ((end_date.getDate()).toString())).slice(-2);
var end_hours = ("00" + (end_date.getHours().toString())).slice(-2);
var end_minutes = ("00" + (end_date.getMinutes().toString())).slice(-2);
var end_seconds = ("00" + (end_date.getSeconds().toString())).slice(-2);
// Since some calendars don't add 0 second events, we need to remove time if there is none...
var start_time = '';
var end_time = '';
if (start_minutes + start_seconds + end_minutes + end_seconds !== 0) {
start_time = 'T' + start_hours + start_minutes + start_seconds;
end_time = 'T' + end_hours + end_minutes + end_seconds;
}
var start = start_year + start_month + start_day + start_time;
var end = end_year + end_month + end_day + end_time;
// recurrence rule vars
var rruleString;
if (rrule) {
if (rrule.rule) {
rruleString = rrule.rule;
} else {
rruleString = 'RRULE:FREQ=' + rrule.freq;
if (rrule.until) {
var uDate = new Date(Date.parse(rrule.until)).toISOString();
rruleString += ';UNTIL=' + uDate.substring(0, uDate.length - 13).replace(/[-]/g, '') + '000000Z';
}
if (rrule.interval) {
rruleString += ';INTERVAL=' + rrule.interval;
}
if (rrule.count) {
rruleString += ';COUNT=' + rrule.count;
}
if (rrule.byday && rrule.byday.length > 0) {
rruleString += ';BYDAY=' + rrule.byday.join(',');
}
}
}
var stamp = new Date().toISOString();
var calendarEvent = [
'BEGIN:VEVENT',
'CLASS:PUBLIC',
'DESCRIPTION:' + description.replace('\r\n', '\\n'),
'DTSTART:' + start,
'DTEND:' + end,
'DTSTAMP:' + stamp.substring(0, stamp.length - 13).replace(/[-]/g, '') + '000000Z',
'LOCATION:' + location,
'SUMMARY;LANGUAGE=en-us:' + subject,
'TRANSP:TRANSPARENT',
'END:VEVENT'
];
if (rruleString) {
calendarEvent.splice(4, 0, rruleString);
}
calendarEvent = calendarEvent.join(SEPARATOR);
calendarEvents.push(calendarEvent);
return calendarEvent;
},
/**
* Download calendar using the saveAs function from filesave.js
* @param {string} filename Filename
* @param {string} ext Extention
*/
'download': function(filename, ext) {
if (calendarEvents.length < 1) {
return false;
}
ext = (typeof ext !== 'undefined') ? ext : '.ics';
filename = (typeof filename !== 'undefined') ? filename : 'calendar';
var calendar = calendarStart + SEPARATOR + calendarEvents.join(SEPARATOR) + calendarEnd;
var blob;
if (navigator.userAgent.indexOf('MSIE 10') === -1) { // chrome or firefox
blob = new Blob([calendar]);
} else { // ie
var bb = new BlobBuilder();
bb.append(calendar);
blob = bb.getBlob('text/x-vCalendar;charset=' + document.characterSet);
}
saveAs(blob, filename + ext);
return calendar;
} }
};
if (rrule.until) {
if (isNaN(Date.parse(rrule.until))) {
throw "Recurrence rule 'until' must be a valid date string";
}
}
if (rrule.interval) {
if (isNaN(parseInt(rrule.interval))) {
throw "Recurrence rule 'interval' must be an integer";
}
}
if (rrule.count) {
if (isNaN(parseInt(rrule.count))) {
throw "Recurrence rule 'count' must be an integer";
}
}
if (typeof rrule.byday !== 'undefined') {
if ( (Object.prototype.toString.call(rrule.byday) !== '[object Array]') ) {
throw "Recurrence rule 'byday' must be an array";
}
if (rrule.byday.length > 7) {
throw "Recurrence rule 'byday' array must not be longer than the 7 days in a week";
}
// Filter any possible repeats
rrule.byday = rrule.byday.filter(function(elem, pos) {
return rrule.byday.indexOf(elem) == pos;
});
for (var d in rrule.byday) {
if (BYDAY_VALUES.indexOf(rrule.byday[d]) < 0) {
throw "Recurrence rule 'byday' values must include only the following: 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'";
}
}
}
}
}
//TODO add time and time zone? use moment to format?
var start_date = new Date(begin);
var end_date = new Date(stop);
var now_date = new Date();
var start_year = ("0000" + (start_date.getFullYear().toString())).slice(-4);
var start_month = ("00" + ((start_date.getMonth() + 1).toString())).slice(-2);
var start_day = ("00" + ((start_date.getDate()).toString())).slice(-2);
var start_hours = ("00" + (start_date.getHours().toString())).slice(-2);
var start_minutes = ("00" + (start_date.getMinutes().toString())).slice(-2);
var start_seconds = ("00" + (start_date.getSeconds().toString())).slice(-2);
var end_year = ("0000" + (end_date.getFullYear().toString())).slice(-4);
var end_month = ("00" + ((end_date.getMonth() + 1).toString())).slice(-2);
var end_day = ("00" + ((end_date.getDate()).toString())).slice(-2);
var end_hours = ("00" + (end_date.getHours().toString())).slice(-2);
var end_minutes = ("00" + (end_date.getMinutes().toString())).slice(-2);
var end_seconds = ("00" + (end_date.getMinutes().toString())).slice(-2);
var now_year = ("0000" + (now_date.getFullYear().toString())).slice(-4);
var now_month = ("00" + ((now_date.getMonth() + 1).toString())).slice(-2);
var now_day = ("00" + ((now_date.getDate()).toString())).slice(-2);
var now_hours = ("00" + (now_date.getHours().toString())).slice(-2);
var now_minutes = ("00" + (now_date.getMinutes().toString())).slice(-2);
var now_seconds = ("00" + (now_date.getMinutes().toString())).slice(-2);
// Since some calendars don't add 0 second events, we need to remove time if there is none...
var start_time = '';
var end_time = '';
if (start_hours + start_minutes + start_seconds + end_hours + end_minutes + end_seconds != 0) {
start_time = 'T' + start_hours + start_minutes + start_seconds;
end_time = 'T' + end_hours + end_minutes + end_seconds;
}
var now_time = 'T' + now_hours + now_minutes + now_seconds;
var start = start_year + start_month + start_day + start_time;
var end = end_year + end_month + end_day + end_time;
var now = now_year + now_month + now_day + now_time;
// recurrence rule vars
var rruleString;
if (rrule) {
if (rrule.rule) {
rruleString = rrule.rule;
} else {
rruleString = 'RRULE:FREQ=' + rrule.freq;
if (rrule.until) {
var uDate = new Date(Date.parse(rrule.until)).toISOString();
rruleString += ';UNTIL=' + uDate.substring(0, uDate.length - 13).replace(/[-]/g, '') + '000000Z';
}
if (rrule.interval) {
rruleString += ';INTERVAL=' + rrule.interval;
}
if (rrule.count) {
rruleString += ';COUNT=' + rrule.count;
}
if (rrule.byday && rrule.byday.length > 0) {
rruleString += ';BYDAY=' + rrule.byday.join(',');
}
}
}
var stamp = new Date().toISOString();
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,
'LOCATION:' + location,
'SUMMARY;LANGUAGE=en-us:' + subject,
'TRANSP:TRANSPARENT',
'END:VEVENT'
];
if (rruleString) {
calendarEvent.splice(4, 0, rruleString);
}
calendarEvent = calendarEvent.join(SEPARATOR);
calendarEvents.push(calendarEvent);
return calendarEvent;
},
/**
* Download calendar using the saveAs function from filesave.js
* @param {string} filename Filename
* @param {string} ext Extention
*/
'download': function(filename, ext) {
if (calendarEvents.length < 1) {
return false;
}
ext = (typeof ext !== 'undefined') ? ext : '.ics';
filename = (typeof filename !== 'undefined') ? filename : 'calendar';
var calendar = calendarStart + SEPARATOR + calendarEvents.join(SEPARATOR) + calendarEnd;
var blob;
if (navigator.userAgent.indexOf('MSIE 10') === -1) { // chrome or firefox
blob = new Blob([calendar]);
} else { // ie
var bb = new BlobBuilder();
bb.append(calendar);
blob = bb.getBlob('text/x-vCalendar;charset=' + document.characterSet);
}
saveAs(blob, filename + ext);
return calendar;
},
/**
* Build and return the ical contents
*/
'build': function() {
if (calendarEvents.length < 1) {
return false;
}
var calendar = calendarStart + SEPARATOR + calendarEvents.join(SEPARATOR) + calendarEnd;
return calendar;
}
};
}; };
+3 -2
View File
@@ -4,12 +4,13 @@
"description": "A browser firendly .ics/.vcs file generator written entirely in javascript", "description": "A browser firendly .ics/.vcs file generator written entirely in javascript",
"main": "icsjs", "main": "icsjs",
"dependencies": { "dependencies": {
"bower": "~1.2.8",
"file-saver": "^1.3.3",
"grunt": "~0.4.2", "grunt": "~0.4.2",
"grunt-contrib-concat": "~0.3.0", "grunt-contrib-concat": "~0.3.0",
"grunt-contrib-jshint": "~0.7.2", "grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-uglify": "~0.2.7", "grunt-contrib-uglify": "~0.2.7",
"grunt-mocha": "~0.4.6", "grunt-mocha": "~0.4.6"
"bower": "~1.2.8"
}, },
"devDependencies": {}, "devDependencies": {},
"scripts": { "scripts": {
+15 -15
View File
@@ -1,24 +1,24 @@
<!doctype html> <!doctype html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Mocha Spec Runner</title> <title>Mocha Spec Runner</title>
<link rel="stylesheet" href="lib/mocha/mocha.css"> <link rel="stylesheet" href="lib/mocha/mocha.css">
</head> </head>
<body> <body>
<div id="mocha"></div> <div id="mocha"></div>
<script src="lib/mocha/mocha.js"></script> <script src="lib/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script> <script>mocha.setup('bdd')</script>
<!-- assertion framework --> <!-- assertion framework -->
<script src="lib/chai.js"></script> <script src="lib/chai.js"></script>
<script>var assert = chai.assert</script> <script>var assert = chai.assert</script>
<!-- include source files here... --> <!-- include source files here... -->
<script src="../ics.js"></script> <script src="../ics.js"></script>
<script>var cal = ics();</script> <script>var cal = ics();</script>
<!-- include spec files here... --> <!-- include spec files here... -->
<script src="spec/test.js"></script> <script src="spec/test.js"></script>
</body> </body>
</html> </html>
+63 -63
View File
@@ -1,71 +1,71 @@
/*global describe, it, cal, assert */ /*global describe, it, cal, assert */
(function () { (function () {
'use strict'; 'use strict';
var stamp = new Date().toISOString(); var stamp = new Date().toISOString();
stamp = stamp.substring(0, stamp.length - 13).replace(/[-]/g, '') + '000000Z'; stamp = stamp.substring(0, stamp.length - 13).replace(/[-]/g, '') + '000000Z';
describe('Load ics Object', function () { describe('Load ics Object', function () {
describe('Calendar Events Array', function () { describe('Calendar Events Array', function () {
it('should be an empty array initially', function () { it('should be an empty array initially', function () {
assert.isArray(cal.events(), 'calendarEvents not an array'); assert.isArray(cal.events(), 'calendarEvents not an array');
assert.lengthOf(cal.events(), '0'); assert.lengthOf(cal.events(), '0');
}); });
});
describe('Calendar String', function () {
it('should be a string with no events', function () {
assert.strictEqual(cal.calendar(), 'BEGIN:VCALENDAR\nVERSION:2.0\n\nEND:VCALENDAR', 'calendar does not match');
});
});
}); });
describe('Add 1 Event', function () { describe('Calendar String', function () {
describe('Calendar Events Array', function () { it('should be a string with no events', function () {
it('should have one event', function () { assert.strictEqual(cal.calendar(), 'BEGIN:VCALENDAR\nVERSION:2.0\n\nEND:VCALENDAR', 'calendar does not match');
cal.addEvent('Christmas', 'Christian holiday celebrating the birth of Jesus Christ', 'Bethlehem', '12/25/2013', '12/25/2013'); });
assert.isArray(cal.events(), 'calendarEvents not an array');
assert.lengthOf(cal.events(), '1');
assert.strictEqual(cal.events()[0], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Christian holiday celebrating the birth of Jesus Christ\nDTSTART:20131225T000000\nDTEND:20131225T000000\nDTSTAMP:' + stamp + '\nLOCATION:Bethlehem\nSUMMARY;LANGUAGE=en-us:Christmas\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
});
describe('Calendar String', function () {
it('should have one event', function () {
assert.strictEqual(cal.calendar(), 'BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Christian holiday celebrating the birth of Jesus Christ\nDTSTART:20131225T000000\nDTEND:20131225T000000\nDTSTAMP:' + stamp + '\nLOCATION:Bethlehem\nSUMMARY;LANGUAGE=en-us:Christmas\nTRANSP:TRANSPARENT\nEND:VEVENT\nEND:VCALENDAR', 'calendar does not match');
});
});
describe('Calendar String of Single Digit Months', function () {
it('should have one event', function () {
cal.addEvent('Easter', 'Christian holiday celebrating the resurrection of Jesus Christ', 'Jerusalem', '04/20/2014', '04/20/2014');
assert.strictEqual(cal.events()[1], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Christian holiday celebrating the resurrection of Jesus Christ\nDTSTART:20140420T000000\nDTEND:20140420T000000\nDTSTAMP:' + stamp + '\nLOCATION:Jerusalem\nSUMMARY;LANGUAGE=en-us:Easter\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
});
describe('Calendar String of Single Digit Day', function () {
it('should have one event', function () {
cal.addEvent('April Fools Day', 'What isn\'t is', 'America', '4/1/2014', '4/1/2014');
assert.strictEqual(cal.events()[2], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:What isn\'t is\nDTSTART:20140401T000000\nDTEND:20140401T000000\nDTSTAMP:' + stamp + '\nLOCATION:America\nSUMMARY;LANGUAGE=en-us:April Fools Day\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
});
describe('Recurring Events', function () {
it('should add recurring events using frequency and until', function () {
cal.addEvent('Soccer Practice', 'Practice kicking the ball in the net! YAYY!!', 'Soccer field', '08/18/2014', '09/18/2014', {freq: 'WEEKLY', until: '08/18/2014'});
assert.strictEqual(cal.events()[3], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Practice kicking the ball in the net! YAYY!!\nDTSTART:20140818T000000\nRRULE:FREQ=WEEKLY;UNTIL=20140818T000000Z\nDTEND:20140918T000000\nDTSTAMP:' + stamp + '\nLOCATION:Soccer field\nSUMMARY;LANGUAGE=en-us:Soccer Practice\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
it('should add recurring events using interval and count', function () {
cal.addEvent('Soccer Practice', 'Practice kicking the ball in the net! YAYY!!', 'Soccer field', '08/18/2014', '09/18/2014', {freq: 'WEEKLY', interval: 2, count: 10});
assert.strictEqual(cal.events()[4], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Practice kicking the ball in the net! YAYY!!\nDTSTART:20140818T000000\nRRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=10\nDTEND:20140918T000000\nDTSTAMP:' + stamp + '\nLOCATION:Soccer field\nSUMMARY;LANGUAGE=en-us:Soccer Practice\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
it('should add recurring events using interval and until and byday', function () {
cal.addEvent('Soccer Practice', 'Practice kicking the ball in the net! YAYY!!', 'Soccer field', '08/18/2014', '09/18/2014', {freq: 'WEEKLY', interval: 1, until: '08/18/2014', byday: ['MO','WE','FR']});
assert.strictEqual(cal.events()[5], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Practice kicking the ball in the net! YAYY!!\nDTSTART:20140818T000000\nRRULE:FREQ=WEEKLY;UNTIL=20140818T000000Z;INTERVAL=1;BYDAY=MO,WE,FR\nDTEND:20140918T000000\nDTSTAMP:' + stamp + '\nLOCATION:Soccer field\nSUMMARY;LANGUAGE=en-us:Soccer Practice\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
it('should add recurring events using interval and until and ignore duplicates in byday array', function () {
cal.addEvent('Soccer Practice', 'Practice kicking the ball in the net! YAYY!!', 'Soccer field', '08/18/2014', '09/18/2014', {freq: 'WEEKLY', interval: 1, until: '08/18/2014', byday: ['MO', 'WE', 'MO']});
assert.strictEqual(cal.events()[6], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Practice kicking the ball in the net! YAYY!!\nDTSTART:20140818T000000\nRRULE:FREQ=WEEKLY;UNTIL=20140818T000000Z;INTERVAL=1;BYDAY=MO,WE\nDTEND:20140918T000000\nDTSTAMP:' + stamp + '\nLOCATION:Soccer field\nSUMMARY;LANGUAGE=en-us:Soccer Practice\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
});
}); });
});
describe('Add 1 Event', function () {
describe('Calendar Events Array', function () {
it('should have one event', function () {
cal.addEvent('Christmas', 'Christian holiday celebrating the birth of Jesus Christ', 'Bethlehem', '12/25/2013', '12/25/2013');
assert.isArray(cal.events(), 'calendarEvents not an array');
assert.lengthOf(cal.events(), '1');
assert.strictEqual(cal.events()[0], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Christian holiday celebrating the birth of Jesus Christ\nDTSTART:20131225T000000\nDTEND:20131225T000000\nDTSTAMP:' + stamp + '\nLOCATION:Bethlehem\nSUMMARY;LANGUAGE=en-us:Christmas\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
});
describe('Calendar String', function () {
it('should have one event', function () {
assert.strictEqual(cal.calendar(), 'BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Christian holiday celebrating the birth of Jesus Christ\nDTSTART:20131225T000000\nDTEND:20131225T000000\nDTSTAMP:' + stamp + '\nLOCATION:Bethlehem\nSUMMARY;LANGUAGE=en-us:Christmas\nTRANSP:TRANSPARENT\nEND:VEVENT\nEND:VCALENDAR', 'calendar does not match');
});
});
describe('Calendar String of Single Digit Months', function () {
it('should have one event', function () {
cal.addEvent('Easter', 'Christian holiday celebrating the resurrection of Jesus Christ', 'Jerusalem', '04/20/2014', '04/20/2014');
assert.strictEqual(cal.events()[1], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Christian holiday celebrating the resurrection of Jesus Christ\nDTSTART:20140420T000000\nDTEND:20140420T000000\nDTSTAMP:' + stamp + '\nLOCATION:Jerusalem\nSUMMARY;LANGUAGE=en-us:Easter\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
});
describe('Calendar String of Single Digit Day', function () {
it('should have one event', function () {
cal.addEvent('April Fools Day', 'What isn\'t is', 'America', '4/1/2014', '4/1/2014');
assert.strictEqual(cal.events()[2], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:What isn\'t is\nDTSTART:20140401T000000\nDTEND:20140401T000000\nDTSTAMP:' + stamp + '\nLOCATION:America\nSUMMARY;LANGUAGE=en-us:April Fools Day\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
});
describe('Recurring Events', function () {
it('should add recurring events using frequency and until', function () {
cal.addEvent('Soccer Practice', 'Practice kicking the ball in the net! YAYY!!', 'Soccer field', '08/18/2014', '09/18/2014', {freq: 'WEEKLY', until: '08/18/2014'});
assert.strictEqual(cal.events()[3], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Practice kicking the ball in the net! YAYY!!\nDTSTART:20140818T000000\nRRULE:FREQ=WEEKLY;UNTIL=20140818T000000Z\nDTEND:20140918T000000\nDTSTAMP:' + stamp + '\nLOCATION:Soccer field\nSUMMARY;LANGUAGE=en-us:Soccer Practice\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
it('should add recurring events using interval and count', function () {
cal.addEvent('Soccer Practice', 'Practice kicking the ball in the net! YAYY!!', 'Soccer field', '08/18/2014', '09/18/2014', {freq: 'WEEKLY', interval: 2, count: 10});
assert.strictEqual(cal.events()[4], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Practice kicking the ball in the net! YAYY!!\nDTSTART:20140818T000000\nRRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=10\nDTEND:20140918T000000\nDTSTAMP:' + stamp + '\nLOCATION:Soccer field\nSUMMARY;LANGUAGE=en-us:Soccer Practice\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
it('should add recurring events using interval and until and byday', function () {
cal.addEvent('Soccer Practice', 'Practice kicking the ball in the net! YAYY!!', 'Soccer field', '08/18/2014', '09/18/2014', {freq: 'WEEKLY', interval: 1, until: '08/18/2014', byday: ['MO','WE','FR']});
assert.strictEqual(cal.events()[5], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Practice kicking the ball in the net! YAYY!!\nDTSTART:20140818T000000\nRRULE:FREQ=WEEKLY;UNTIL=20140818T000000Z;INTERVAL=1;BYDAY=MO,WE,FR\nDTEND:20140918T000000\nDTSTAMP:' + stamp + '\nLOCATION:Soccer field\nSUMMARY;LANGUAGE=en-us:Soccer Practice\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
it('should add recurring events using interval and until and ignore duplicates in byday array', function () {
cal.addEvent('Soccer Practice', 'Practice kicking the ball in the net! YAYY!!', 'Soccer field', '08/18/2014', '09/18/2014', {freq: 'WEEKLY', interval: 1, until: '08/18/2014', byday: ['MO', 'WE', 'MO']});
assert.strictEqual(cal.events()[6], 'BEGIN:VEVENT\nCLASS:PUBLIC\nDESCRIPTION:Practice kicking the ball in the net! YAYY!!\nDTSTART:20140818T000000\nRRULE:FREQ=WEEKLY;UNTIL=20140818T000000Z;INTERVAL=1;BYDAY=MO,WE\nDTEND:20140918T000000\nDTSTAMP:' + stamp + '\nLOCATION:Soccer field\nSUMMARY;LANGUAGE=en-us:Soccer Practice\nTRANSP:TRANSPARENT\nEND:VEVENT');
});
});
});
})(); })();