Skip to content

Commit

Permalink
* Added millisecond precision note to change log
Browse files Browse the repository at this point in the history
* camel cased changes in rule/js and tests/utils.js
* removed setMilliseconds(0) call from clone
  • Loading branch information
paulbalomiri committed Apr 30, 2015
1 parent 2aac72e commit a349aca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 16 additions & 17 deletions lib/rrule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

Expand Down Expand Up @@ -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 = {
Expand All @@ -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;
}
};

Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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)];
};


Expand Down
4 changes: 2 additions & 2 deletions tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a349aca

Please sign in to comment.