Skip to content

Commit

Permalink
fix issue #1 (yearly parsing)
Browse files Browse the repository at this point in the history
  • Loading branch information
skyporter committed Jan 9, 2012
1 parent e618efb commit 5ae723f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
19 changes: 16 additions & 3 deletions rrecur-parser-tests.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* ----------------------------------------------------------------------------
Testing case of rrecur-parser.js inspired from
Testing case of scheduler.js inspired from
http://www.kanzaki.com/docs/ical/rrule.html
date : dec 14 2011
date : jan 09 2012
---------------------------------------------------------------------------- */

Expand Down Expand Up @@ -802,4 +802,17 @@ console.assert(occurrences.in_array(new Date(1997, 7, 5, 9).getTime()));
console.assert(occurrences.in_array(new Date(1997, 7, 17, 9).getTime()));
console.assert(occurrences.in_array(new Date(1997, 7, 19, 9).getTime()));
console.assert(occurrences.in_array(new Date(1997, 7, 31, 9).getTime()));
// ==> (1997 EDT)August 5,17,19,31
// ==> (1997 EDT)August 5,17,19,31


console.log("--- Birthday ---");
d = new Date(2011, 0, 1);
start_at = new Date(2011, 0, 1);
end_at = new Date(2014, 0, 1);
scheduler = new Scheduler(d, "FREQ=YEARLY;INTERVAL=1", true);
occurrences = scheduler.occurrences_between(start_at, end_at);
console.assert(occurrences.length == 4);
console.assert(occurrences[0] == new Date(2011, 0, 1).getTime());
console.assert(occurrences[1] == new Date(2012, 0, 1).getTime());
console.assert(occurrences[2] == new Date(2013, 0, 1).getTime());
console.assert(occurrences[3] == new Date(2014, 0, 1).getTime());
31 changes: 28 additions & 3 deletions rrecur-parser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
// used for IE < 9
// adapted from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length >>> 0;

var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from += len;

for (; from < len; from++)
{
if (from in this &&
this[from] === elt)
return from;
}
return -1;
};
}

Array.prototype.in_array = function(test_var) { // useful method for "class" Array
return this.indexOf(test_var, 0) != -1;
}
Expand Down Expand Up @@ -268,9 +293,9 @@ Scheduler.prototype.add_recurrence_rules = function(rfc_rrule) {
if (!this.rrule_byday && !this.rrule_bymonthday && !this.rrule_byyearday && (this.rrule_freq == "MONTHLY" || this.rrule_freq == "YEARLY")) {
this.rrule_bymonthday = [ this.start_date.getDate().toString() ];
}
// if (!this.rrule_bymonth && (this.rrule_freq == "YEARLY")) {
// this.rrule_bymonth = [ (this.start_date.getMonth() + 1).toString() ];
// }
if (!this.rrule_byday && !this.rrule_byyearday && !this.rrule_bymonth && this.rrule_freq == "YEARLY") {
this.rrule_bymonth = [ (this.start_date.getMonth() + 1).toString() ];
}
}

// removes all RRULEs
Expand Down
12 changes: 12 additions & 0 deletions test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="./rrecur-parser.js" ></script>
<script type="text/javascript" src="./rrecur-parser-tests.js" ></script>
<title>Tests parseur</title>
</head>
<body>
Done !
</body>
</html>

0 comments on commit 5ae723f

Please sign in to comment.