Commit 05514359 authored by Sebastian Pekarek's avatar Sebastian Pekarek
Browse files

Repeating: byMonth, byMonthDay

parent 1871ec7a
......@@ -285,7 +285,10 @@ event.repeating({
freq: 'MONTHLY', // required
count: 5,
interval: 2,
until: new Date('Jan 01 2014 00:00:00 UTC')
until: new Date('Jan 01 2014 00:00:00 UTC'),
byDay: ['su', 'mo'], // repeat only sunday and monday
byMonth: [1, 2], // repeat only in january und february,
byMonthDay: [1, 15] // repeat only on the 1st and 15th
});
```
......
......@@ -225,12 +225,50 @@ var ICalEvent = function(_data) {
data.repeating.until = repeating.until;
}
if(repeating.byday) {
if(!Array.isArray(repeating.byday)){
throw '`repeating.byday` must be an Array of day symbols!';
if(repeating.byDay) {
if(!Array.isArray(repeating.byDay)){
throw '`repeating.byDay` must be an Array of day symbols!';
}
data.repeating.byday = repeating.byday;
data.repeating.byDay = [];
repeating.byDay.forEach(function(symbol) {
var s = symbol.toString().toUpperCase();
if(['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'].indexOf(s) === -1) {
throw '`repeating.byDay` contains invalid value `' + s + '`!';
}
data.repeating.byDay.push(s);
});
}
if(repeating.byMonth) {
if(!Array.isArray(repeating.byMonth)){
throw '`repeating.byMonth` must be an Array of numbers!';
}
data.repeating.byMonth = [];
repeating.byMonth.forEach(function(month) {
if(typeof month !== 'number' || month < 1 || month > 12) {
throw '`repeating.byMonth` contains invalid value `' + month + '`!';
}
data.repeating.byMonth.push(month);
});
}
if(repeating.byMonthDay) {
if(!Array.isArray(repeating.byMonthDay)){
throw '`repeating.byMonthDay` must be an Array of numbers!';
}
data.repeating.byMonthDay = [];
repeating.byMonthDay.forEach(function(monthDay) {
if(typeof monthDay !== 'number' || monthDay < 1 || monthDay > 31) {
throw '`repeating.byMonthDay` contains invalid value `' + monthDay + '`!';
}
data.repeating.byMonthDay.push(monthDay);
});
}
return this;
......@@ -530,8 +568,16 @@ var ICalEvent = function(_data) {
g += ';UNTIL=' + tools.formatDate(data.repeating.until);
}
if(data.repeating.byday) {
g += ';BYDAY=' + data.repeating.byday.join(',');
if(data.repeating.byDay) {
g += ';BYDAY=' + data.repeating.byDay.join(',');
}
if(data.repeating.byMonth) {
g += ';BYMONTH=' + data.repeating.byMonth.join(',');
}
if(data.repeating.byMonthDay) {
g += ';BYMONTHDAY=' + data.repeating.byMonthDay.join(',');
}
g += '\r\n';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment