Permalink
Browse files

fixed "day" occurrence not outputing. updated docs

  • Loading branch information...
1 parent 1a52fdb commit 09b997d6031de47c5c96c26cfd5987d59e83919c @mooman committed Sep 8, 2010
Showing with 50 additions and 14 deletions.
  1. +43 −12 README.md
  2. +6 −2 recurrence.js
  3. +1 −0 spec/recurrence_spec.js
View
@@ -3,19 +3,23 @@ JavaScript library to generate recurring dates.
For example:
-Every 2 weeks on Monday, Wednesday, and Friday starting today for 5 occurrences
+Every 2 weeks on Monday, Wednesday, and Friday starting today for 5 occurrences
Every month on the last Sunday starting on 02/10/09 until 03/30/10
This library will generate a list of dates for those patterns.
+Please see demo here:
+http://mooman.github.com/recurring_dates/demo.html
+
REQUIREMENTS
------------
-Datejs - http://www.datejs.com/
+Datejs - http://www.datejs.com/
(Distributed with this is the SVN version from 03/29/2010. Please visit their site also.)
-Prototype - http://www.prototypejs.org/ (though this library can be easily modified to use other js frameworks)
+Prototype - http://www.prototypejs.org/
+(Mainly for the Class.create and Array#each. A future release will free this dependency)
USAGE
@@ -36,13 +40,21 @@ where pattern is a JSON object with the following options:
- start: start date. date. required.
- every: interval magnitude (every XXX weeks...). integer. required.
-- unit: valid values are 'd', 'w', 'm', 'y' for days, weeks, months, and years respectively. probably required.
-- end_condition: how should the recurrence be terminated. valid values are 'until' and 'for'. until should be a date. for should be an integer (for N occurrences). required.
+- unit: valid values are 'd', 'w', 'm', 'y' for days, weeks, months, and years
+ respectively. probably required.
+- end_condition: how should the recurrence be terminated.
+ valid values are 'until' and 'for'. 'until' should be a date.
+ 'for' should be an integer (for N occurrences). required.
- until: if end_condition is 'until', pass the date here.
- rfor: if end_condition is 'for', pass an integer here.
-- nth: valid values are 'first', 'second', 'third', 'forth', and 'last'. see 'occurrence_of' option. to be used with 'm' unit option.
-- occurrence_of: valid values are 0-6, corresponding to the days of the week. in conjuction with 'nth' option, specifies nth day of the month (last Sunday of the month). to be used with 'm' unit option.
-- days: to be used with 'w' unit option. an array of integers representing day of the week (0-6). eg. Every 2 weeks on Tuesday (2) and Thursday (4), pass [2,4] as the value.
+- nth: valid values are 'first', 'second', 'third', 'forth', and 'last'.
+ see 'occurrence_of' option. to be used with 'm' unit option.
+- occurrence_of: valid values are 0-6, corresponding to the days of the week.
+ in conjuction with 'nth' option, specifies nth day of the month
+ (last Sunday of the month). to be used with 'm' unit option.
+- days: to be used with 'w' unit option. an array of integers representing day
+ of the week (0-6). eg. Every 2 weeks on Tuesday (2) and Thursday (4),
+ pass [2,4] as the value.
ex.
{ start: Date.today(), every: 2, unit: 'w', end_condition: 'for', rfor: 5, days: [1,3,5] }
@@ -61,21 +73,40 @@ Tries to describe the supplied pattern in English.
Boolean contains (date)
-Determines whether "date" is in the recurrence pattern. This calls generate(), if it hasn't already been generated, otherwise, it will use the dates generated from the last time generate() was called. Returns true if "date" is in the pattern. "date" can be either a string or a Date object, but please make sure the time portion is all balls.
+Determines whether "date" is in the recurrence pattern. This calls generate(),
+if it hasn't already been generated, otherwise, it will use the dates generated
+from the last time generate() was called. Returns true if "date" is in the pattern.
+"date" can be either a string or a Date object, but please make sure the time
+portion is all balls (00:00:00).
-Note that this only check if "date" is contained within the pattern's starting and ending points. Next version will support indefinite ending date and throwaway dates generation, instead of storing them all in an array.
+Note that this only check if "date" is contained within the pattern's starting and
+ending points. Next version will support indefinite ending date and throwaway dates
+generation, instead of storing them all in an array.
-----
Date[] generate ([limit])
-Generate the dates based on supplied pattern. Returns array of Date objects. Optional argument limit puts an upper limit on how many dates to generate (for preview or to prevent some memory leak).
+Generate the dates based on supplied pattern. Returns array of Date objects.
+Optional argument limit puts an upper limit on how many dates to generate
+(for preview or to prevent some memory leak).
+
+
+TODO
+----
+
+- Remove Prototype dependency
+ + use something else other than Class.create
+ + replace Array.each with for loops
+- Indefinite ending date
+- Throwaway date generation (not store in array, but just output it)
COMMENTS
--------
-Please feel free fork and improve, submit bug reports, suggestions, comments. email: janechii AT gmail.
+Please feel free fork and improve, submit bug reports, suggestions, comments.
+email: janechii AT gmail.
LICENSE
View
@@ -52,7 +52,7 @@ var Recurrence = Class.create({
// tries to describe the pattern in plain english
describe: function () {
var units = {'d': 'day', 'w': 'week', 'm': 'month', 'y': 'year'};
- var week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
+ var week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'day'];
var nthword = ['', 'first', 'second', 'third', 'forth', 'fifth', 'last']
var t = ['Every'];
@@ -71,7 +71,11 @@ var Recurrence = Class.create({
}
t.push('on', d.join(', '));
} else if (this.unit == 'm') {
- t.push('on the', nthword[(this.nth < 0) ? nthword.length-1 : this.nth], week[this.occurrence_of]);
+ // check if it's a special word
+ day_idx = (this.occurrence_of < 0) ? week.length - 1 : this.occurrence_of;
+ nth_idx = (this.nth < 0) ? nthword.length-1 : this.nth;
+
+ t.push('on the', nthword[nth_idx], week[day_idx]);
}
t.push('starting on', this.start.toString(this.date_format));
View
@@ -81,6 +81,7 @@ Screw.Unit(function () {
test_dates(pattern, expected_dates);
});
+ // definitely needs more work
it('#describe', function () {
var r = new Recurrence(base_pattern);

0 comments on commit 09b997d

Please sign in to comment.