diff --git a/README.md b/README.md index 17639418..a6b5de75 100644 --- a/README.md +++ b/README.md @@ -455,10 +455,12 @@ var rule = new RRule(options) * * * * * ### Changelog - * 2.1.0 * Removed dependency on Underscore.js (thanks @gsf). * Various small bugfixes and improvements. + * Added Millisecond precision + * millisecond offset extracted ftom dtstart (dtstart.getTime()%1000) + * each reccurence is returned with the same offset * 2.0.1 * Added bower.json. * 2.0.0 (2013-07-16) diff --git a/lib/rrule.js b/lib/rrule.js index bfb54789..a76bea4c 100644 --- a/lib/rrule.js +++ b/lib/rrule.js @@ -155,13 +155,12 @@ var dateutil = { time = time || date; return new Date( date.getFullYear(), date.getMonth(), date.getDate(), - time.getHours(), time.getMinutes(), time.getSeconds(), time.getSubSeconds() + time.getHours(), time.getMinutes(), time.getSeconds(), time.getMilliseconds() ); }, clone: function(date) { var dolly = new Date(date.getTime()); - dolly.setMilliseconds(0); return dolly; }, @@ -221,11 +220,11 @@ var dateutil = { }; -dateutil.Time = function(hour, minute, second, sub_second) { +dateutil.Time = function(hour, minute, second, millisecond) { this.hour = hour; this.minute = minute; this.second = second; - this.sub_second = sub_second || 0; + this.millisecond = millisecond || 0; }; dateutil.Time.prototype = { @@ -238,14 +237,14 @@ dateutil.Time.prototype = { getSeconds: function() { return this.second; }, - getSubSeconds: function(){ - return this.sub_second + getMilliseconds: function(){ + return this.millisecond }, getTime: function() { return ((this.hour * 60 * 60) + (this.minute * 60) + this.second) - * 1000 + this.sub_second; + * 1000 + this.millisecond; } }; @@ -506,7 +505,7 @@ var RRule = function(options, noCache) { if (!opts.dtstart) { opts.dtstart = new Date(); } - var sub_second_mod = opts.dtstart.getTime()%1000; + var millisecondModulo = opts.dtstart.getTime()%1000; if (opts.wkst === null) { opts.wkst = RRule.MO.weekday; } else if (typeof opts.wkst == 'number') { @@ -674,7 +673,7 @@ var RRule = function(options, noCache) { // python: // datetime.time(hour, minute, second, // tzinfo=self._tzinfo)) - this.timeset.push(new dateutil.Time(hour, minute, second, sub_second_mod)); + this.timeset.push(new dateutil.Time(hour, minute, second, millisecondModulo)); } } } @@ -1026,7 +1025,7 @@ RRule.prototype = { */ var dtstart = this.options.dtstart, - dtstart_subsecond_mod= this.options.dtstart%1000; + dtstartMillisecondModulo= this.options.dtstart%1000; var year = dtstart.getFullYear(), @@ -1085,7 +1084,7 @@ RRule.prototype = { { timeset = []; } else { - timeset = gettimeset.call(ii, hour, minute, second, dtstart_subsecond_mod); + timeset = gettimeset.call(ii, hour, minute, second, dtstartMillisecondModulo); } } @@ -1738,31 +1737,31 @@ Iterinfo.prototype.ddayset = function(year, month, day) { return [set, i, i + 1]; }; -Iterinfo.prototype.htimeset = function(hour, minute, second, sub_second) { +Iterinfo.prototype.htimeset = function(hour, minute, second, millisecond) { var set = [], rr = this.rrule; for (var i = 0; i < rr.options.byminute.length; i++) { minute = rr.options.byminute[i]; for (var j = 0; j < rr.options.bysecond.length; j++) { second = rr.options.bysecond[j]; - set.push(new dateutil.Time(hour, minute, second,sub_second)); + set.push(new dateutil.Time(hour, minute, second,millisecond)); } } dateutil.sort(set); return set; }; -Iterinfo.prototype.mtimeset = function(hour, minute, second,sub_second) { +Iterinfo.prototype.mtimeset = function(hour, minute, second,millisecond) { var set = [], rr = this.rrule; for (var j = 0; j < rr.options.bysecond.length; j++) { second = rr.options.bysecond[j]; - set.push(new dateutil.Time(hour, minute, second,sub_second)); + set.push(new dateutil.Time(hour, minute, second,millisecond)); } dateutil.sort(set); return set; }; -Iterinfo.prototype.stimeset = function(hour, minute, second,sub_second) { - return [new dateutil.Time(hour, minute, second,sub_second)]; +Iterinfo.prototype.stimeset = function(hour, minute, second,millisecond) { + return [new dateutil.Time(hour, minute, second,millisecond)]; }; diff --git a/tests/utils.js b/tests/utils.js index 72925913..cf68cbb3 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -54,7 +54,7 @@ var assertDatesEqual = function(actual, expected, msg) { } }; -var extract_time = function(date) { +var extractTime = function(date) { return date != null ? date.getTime() : void 0; } var testRecurring = function(msg, rruleOrObj, expectedDates) { @@ -93,7 +93,7 @@ var testRecurring = function(msg, rruleOrObj, expectedDates) { if(this.ALSO_TEST_SUBSECOND_PRECISION) - deepEqual( actualDates.map(extract_time), expectedDates.map(extract_time)); + deepEqual( actualDates.map(extractTime), expectedDates.map(extractTime)); if (this.ALSO_TEST_STRING_FUNCTIONS) { // Test toString()/fromString() var string = rrule.toString();