Comparing version 1.1.10 to 1.1.11
@@ -87,2 +87,3 @@ /* ------------------------------------------------------------------------------------ | ||
function CronDate (date) { | ||
this.seconds = date.getSeconds() + 1; | ||
@@ -96,19 +97,21 @@ this.minutes = date.getMinutes(); | ||
CronDate.prototype.findNext = function (target, pattern, offset, override) { | ||
var startPos = (override === void 0) ? this[target] + offset : 0 + offset; | ||
CronDate.prototype.increment = function (pattern) { | ||
for (var i = startPos; i < pattern[target].length; i++) { | ||
if (pattern[target][i]) { | ||
this[target] = i-offset; | ||
return true; | ||
} | ||
} | ||
var self = this, | ||
return false; | ||
findNext = function (target, pattern, offset, override) { | ||
var startPos = (override === void 0) ? self[target] + offset : 0 + offset; | ||
}; | ||
for (var i = startPos; i < pattern[target].length; i++) { | ||
if (pattern[target][i]) { | ||
self[target] = i-offset; | ||
return true; | ||
} | ||
} | ||
CronDate.prototype.increment = function (pattern) { | ||
return false; | ||
}; | ||
// Array of work to be done, consisting of subarrays described below: | ||
@@ -137,3 +140,3 @@ // [ | ||
// be set to 5 | ||
if(!this.findNext(toDo[doing][0], pattern, toDo[doing][2])) { | ||
if(!findNext(toDo[doing][0], pattern, toDo[doing][2])) { | ||
@@ -154,3 +157,3 @@ // If pattern didn't provide a match, increment next vanlue (e.g. minues) | ||
// from zero, instead of current time. | ||
this.findNext(toDo[doing][0], pattern, toDo[doing][2], 0); | ||
findNext(toDo[doing][0], pattern, toDo[doing][2], 0); | ||
@@ -249,6 +252,2 @@ // Go back up, days -> hours -> minutes -> seconds | ||
// 0 = Sunday, 7 = Sunday | ||
if (this.daysOfWeek[0]) { | ||
this.daysOfWeek[7] = 1; | ||
} | ||
if (this.daysOfWeek[7]) { | ||
@@ -428,9 +427,7 @@ this.daysOfWeek[0] = 1; | ||
// Check if stopAt has passed, in that case return undefined | ||
// Get next run | ||
nextRun = cronDate.getDate(); | ||
if(stopAt && nextRun >= stopAt ) | ||
return undefined; | ||
// All seem good, return next run | ||
return nextRun; | ||
return !(stopAt && nextRun >= stopAt ) ? nextRun : undefined; | ||
}; | ||
@@ -437,0 +434,0 @@ |
// Licenced under MIT - croner - ©2016 Hexagon <github.com/hexagon> | ||
(function(){"use strict";function c(a){throw new TypeError("Cron parser: "+a)}function d(){var a=new Date;return a.setMilliseconds(0),a}function e(a,b){for(var c=0;c<a.length;c++)a[c]=b;return a}function f(a){this.seconds=a.getSeconds()+1,this.minutes=a.getMinutes(),this.hours=a.getHours(),this.days=a.getDate(),this.months=a.getMonth(),this.years=a.getFullYear()}function g(a){this.pattern=a,this.seconds=e(Array(60),0),this.minutes=e(Array(60),0),this.hours=e(Array(24),0),this.days=e(Array(31),0),this.months=e(Array(12),0),this.daysOfWeek=e(Array(8),0),this.parse()}function h(a,b,c){var d=this;return this instanceof h?(d.pattern=new g(a),d.schedulerDefaults={stopAt:1/0,maxRuns:1/0,kill:!1},"function"==typeof b&&(c=b,b={}),d.opts=d.validateOpts(b||{}),"undefined"==typeof c?d:this.schedule(b,c)):new h(a,b,c)}var a=this,b=Math.pow(2,31)-1;f.prototype.findNext=function(a,b,c,d){for(var e=void 0===d?this[a]+c:0+c,f=e;f<b[a].length;f++)if(b[a][f])return this[a]=f-c,!0;return!1},f.prototype.increment=function(a){for(var b=[["seconds","minutes",0],["minutes","hours",0],["hours","days",0],["days","months",-1],["months","years",0]],c=0;c<5;){if(!this.findNext(b[c][0],a,b[c][2]))for(this[b[c][1]]++;c>=0;)this.findNext(b[c][0],a,b[c][2],0),c--;c++}for(;!a.daysOfWeek[this.getDate().getDay()];)this.days+=1},f.prototype.getDate=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,0)},g.prototype.parse=function(){"string"!=typeof this.pattern&&c("invalid configuration string ('"+this.pattern+"').");var b,d,f,g,h,a=this.pattern.trim().replace(/\s+/g," ").split(" "),e=/[^\/\*0-9,-]+/;for(6!==a.length&&c("invalid configuration format ('"+this.pattern+"'), exacly five space separated parts required."),d=0;d<a.length;d++)b=a[d].trim(),e.test(b)&&c("configuration entry "+(d+1)+" ("+b+") contains illegal characters.");f="*"!==a[4],g="*"!==a[5],h="*"!==a[3],g&&(f||h)&&c("configuration invalid, you can not combine month/date with day of week."),this.partToArray("seconds",a[0],0),this.partToArray("minutes",a[1],0),this.partToArray("hours",a[2],0),this.partToArray("days",a[3],-1),this.partToArray("months",a[4],-1),this.partToArray("daysOfWeek",a[5],0),this.daysOfWeek[0]&&(this.daysOfWeek[7]=1),this.daysOfWeek[7]&&(this.daysOfWeek[0]=1)},g.prototype.partToArray=function(a,b,d){var e,f,g,h,i,j=this[a];if("*"!==b)if(f=b.split(","),f.length>1)for(e=0;e<f.length;e++)this.partToArray(a,f[e],d);else if(b.indexOf("-")!==-1)for(f=b.split("-"),2!==f.length&&c("Syntax error, illegal range: '"+b+"'"),g=parseInt(f[0],10)+d,h=parseInt(f[1],10)+d,isNaN(g)?c("Syntax error, illegal lower range (NaN)"):isNaN(h)&&c("Syntax error, illegal upper range (NaN)"),(g<0||h>=j.length)&&c("Value out of range: '"+b+"'"),g>h&&c("From value is larger than to value: '"+b+"'"),e=g;e<=h;e++)j[e+d]=1;else if(b.indexOf("/")!==-1)for(f=b.split("/"),2!==f.length&&c("Syntax error, illegal stepping: '"+b+"'"),"*"!==f[0]&&c("Syntax error, left part of / needs to be * : '"+b+"'"),i=parseInt(f[1],10),isNaN(i)&&c("Syntax error, illegal stepping: (NaN)"),0===i&&c("Syntax error, illegal stepping: 0"),i>j.length&&c("Syntax error, steps cannot be greater than maximum value of part ("+j.length+")"),e=0;e<j.length;e+=i)j[e+d]=1;else e=parseInt(b,10)+d,(e<0||e>=j.length)&&c(a+" value out of range: '"+b+"'"),j[e]=1;else for(e=0;e<j.length;e++)j[e]=1},h.prototype.next=function(a){this.opts.startAt&&a<this.opts.startAt&&(a=this.opts.startAt),a=a||this.opts.startAt||d();var e,b=this.opts.stopAt||this.schedulerDefaults.stopAt,c=new f(a);if(c.increment(this.pattern),e=c.getDate(),!(b&&e>=b))return e},h.prototype.validateOpts=function(a){return void 0!==a.startAt&&(a.startAt.constructor!==Date?a.startAt=new Date(Date.parse(a.startAt)-1):a.startAt=new Date(a.startAt.getTime()-1),isNaN(a.startAt)&&c("Provided value for startAt could not be parsed as date.")),void 0!==a.stopAt&&(a.stopAt.constructor!==Date&&(a.stopAt=new Date(Date.parse(a.stopAt))),isNaN(a.stopAt)&&c("Provided value for stopAt could not be parsed as date.")),a},h.prototype.msToNext=function(a){a=a||d();var b=this.next(a);return b?this.next(a)-a.getTime():b},h.prototype.schedule=function(a,c){var f,e=this,g=e.maxDelay||b;if(c||(c=a,a={}),a.paused="undefined"!=typeof a.paused&&a.paused,a.kill=a.kill||this.schedulerDefaults.kill,a.rest=a.rest||0,a.maxRuns||0===a.maxRuns||(a.maxRuns=this.schedulerDefaults.maxRuns),e.opts=e.validateOpts(a||{}),f=this.msToNext(a.previous),!(a.maxRuns<=0||void 0===f||a.kill))return f>g&&(f=g),a.currentTimeout=setTimeout(function(){f===g||a.paused||(a.maxRuns--,a.previous=d(),c()),a.paused&&(a.previous=d()),e.schedule(a,c)},f),{stop:function(){a.kill=!0,a.currentTimeout&&clearTimeout(a.currentTimeout)},pause:function(){return(a.paused=!0)&&!a.kill},resume:function(){return!(a.paused=!1)&&!a.kill}}},"undefined"!=typeof module&&"object"==typeof module.exports?module.exports=h:"function"==typeof define&&define.amd?define([],function(){return h}):a.Cron=h}).call(this); | ||
(function(){"use strict";function c(a){throw new TypeError("Cron parser: "+a)}function d(){var a=new Date;return a.setMilliseconds(0),a}function e(a,b){for(var c=0;c<a.length;c++)a[c]=b;return a}function f(a){this.seconds=a.getSeconds()+1,this.minutes=a.getMinutes(),this.hours=a.getHours(),this.days=a.getDate(),this.months=a.getMonth(),this.years=a.getFullYear()}function g(a){this.pattern=a,this.seconds=e(Array(60),0),this.minutes=e(Array(60),0),this.hours=e(Array(24),0),this.days=e(Array(31),0),this.months=e(Array(12),0),this.daysOfWeek=e(Array(8),0),this.parse()}function h(a,b,c){var d=this;return this instanceof h?(d.pattern=new g(a),d.schedulerDefaults={stopAt:1/0,maxRuns:1/0,kill:!1},"function"==typeof b&&(c=b,b={}),d.opts=d.validateOpts(b||{}),"undefined"==typeof c?d:this.schedule(b,c)):new h(a,b,c)}var a=this,b=Math.pow(2,31)-1;f.prototype.increment=function(a){for(var b=this,c=function(a,c,d,e){for(var f=void 0===e?b[a]+d:0+d,g=f;g<c[a].length;g++)if(c[a][g])return b[a]=g-d,!0;return!1},d=[["seconds","minutes",0],["minutes","hours",0],["hours","days",0],["days","months",-1],["months","years",0]],e=0;e<5;){if(!c(d[e][0],a,d[e][2]))for(this[d[e][1]]++;e>=0;)c(d[e][0],a,d[e][2],0),e--;e++}for(;!a.daysOfWeek[this.getDate().getDay()];)this.days+=1},f.prototype.getDate=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,0)},g.prototype.parse=function(){"string"!=typeof this.pattern&&c("invalid configuration string ('"+this.pattern+"').");var b,d,f,g,h,a=this.pattern.trim().replace(/\s+/g," ").split(" "),e=/[^\/\*0-9,-]+/;for(6!==a.length&&c("invalid configuration format ('"+this.pattern+"'), exacly five space separated parts required."),d=0;d<a.length;d++)b=a[d].trim(),e.test(b)&&c("configuration entry "+(d+1)+" ("+b+") contains illegal characters.");f="*"!==a[4],g="*"!==a[5],h="*"!==a[3],g&&(f||h)&&c("configuration invalid, you can not combine month/date with day of week."),this.partToArray("seconds",a[0],0),this.partToArray("minutes",a[1],0),this.partToArray("hours",a[2],0),this.partToArray("days",a[3],-1),this.partToArray("months",a[4],-1),this.partToArray("daysOfWeek",a[5],0),this.daysOfWeek[7]&&(this.daysOfWeek[0]=1)},g.prototype.partToArray=function(a,b,d){var e,f,g,h,i,j=this[a];if("*"!==b)if(f=b.split(","),f.length>1)for(e=0;e<f.length;e++)this.partToArray(a,f[e],d);else if(b.indexOf("-")!==-1)for(f=b.split("-"),2!==f.length&&c("Syntax error, illegal range: '"+b+"'"),g=parseInt(f[0],10)+d,h=parseInt(f[1],10)+d,isNaN(g)?c("Syntax error, illegal lower range (NaN)"):isNaN(h)&&c("Syntax error, illegal upper range (NaN)"),(g<0||h>=j.length)&&c("Value out of range: '"+b+"'"),g>h&&c("From value is larger than to value: '"+b+"'"),e=g;e<=h;e++)j[e+d]=1;else if(b.indexOf("/")!==-1)for(f=b.split("/"),2!==f.length&&c("Syntax error, illegal stepping: '"+b+"'"),"*"!==f[0]&&c("Syntax error, left part of / needs to be * : '"+b+"'"),i=parseInt(f[1],10),isNaN(i)&&c("Syntax error, illegal stepping: (NaN)"),0===i&&c("Syntax error, illegal stepping: 0"),i>j.length&&c("Syntax error, steps cannot be greater than maximum value of part ("+j.length+")"),e=0;e<j.length;e+=i)j[e+d]=1;else e=parseInt(b,10)+d,(e<0||e>=j.length)&&c(a+" value out of range: '"+b+"'"),j[e]=1;else for(e=0;e<j.length;e++)j[e]=1},h.prototype.next=function(a){this.opts.startAt&&a<this.opts.startAt&&(a=this.opts.startAt),a=a||this.opts.startAt||d();var e,b=this.opts.stopAt||this.schedulerDefaults.stopAt,c=new f(a);return c.increment(this.pattern),e=c.getDate(),b&&e>=b?void 0:e},h.prototype.validateOpts=function(a){return void 0!==a.startAt&&(a.startAt.constructor!==Date?a.startAt=new Date(Date.parse(a.startAt)-1):a.startAt=new Date(a.startAt.getTime()-1),isNaN(a.startAt)&&c("Provided value for startAt could not be parsed as date.")),void 0!==a.stopAt&&(a.stopAt.constructor!==Date&&(a.stopAt=new Date(Date.parse(a.stopAt))),isNaN(a.stopAt)&&c("Provided value for stopAt could not be parsed as date.")),a},h.prototype.msToNext=function(a){a=a||d();var b=this.next(a);return b?this.next(a)-a.getTime():b},h.prototype.schedule=function(a,c){var f,e=this,g=e.maxDelay||b;if(c||(c=a,a={}),a.paused="undefined"!=typeof a.paused&&a.paused,a.kill=a.kill||this.schedulerDefaults.kill,a.rest=a.rest||0,a.maxRuns||0===a.maxRuns||(a.maxRuns=this.schedulerDefaults.maxRuns),e.opts=e.validateOpts(a||{}),f=this.msToNext(a.previous),!(a.maxRuns<=0||void 0===f||a.kill))return f>g&&(f=g),a.currentTimeout=setTimeout(function(){f===g||a.paused||(a.maxRuns--,a.previous=d(),c()),a.paused&&(a.previous=d()),e.schedule(a,c)},f),{stop:function(){a.kill=!0,a.currentTimeout&&clearTimeout(a.currentTimeout)},pause:function(){return(a.paused=!0)&&!a.kill},resume:function(){return!(a.paused=!1)&&!a.kill}}},"undefined"!=typeof module&&"object"==typeof module.exports?module.exports=h:"function"==typeof define&&define.amd?define([],function(){return h}):a.Cron=h}).call(this); |
{ | ||
"name": "croner", | ||
"version": "1.1.10", | ||
"version": "1.1.11", | ||
"description": "Isomorphic JavaScript cron parser and scheduler.", | ||
@@ -5,0 +5,0 @@ "author": "Hexagon <github.com/hexagon>", |
@@ -269,5 +269,13 @@ /* | ||
nextRun = scheduler.next(), | ||
// ToDay/nextDay is a fix for DST in test | ||
toDay = new Date(), | ||
nextDay = new Date(new Date().getTime()+24*60*60*1000); // Add one day | ||
// Set seconds, minutes and hours to 00:00:00 | ||
toDay.setMilliseconds(0); | ||
toDay.setSeconds(0); | ||
toDay.setMinutes(0); | ||
toDay.setHours(0); | ||
nextDay = new Date(toDay.getTime()+36*60*60*1000); | ||
nextDay.setMilliseconds(0); | ||
@@ -278,2 +286,3 @@ nextDay.setSeconds(0); | ||
// Do comparison | ||
@@ -448,2 +457,21 @@ nextRun.getTime().should.equal(nextDay.getTime()); | ||
it("Weekday 0 (sunday) and weekday 7 (sunday) should both be valid patterns", function () { | ||
(function () { | ||
var | ||
scheduler0 = new Cron("0 0 0 * * 0"), | ||
nextRun0 = scheduler0.next(), | ||
scheduler7 = new Cron("0 0 0 * * 7"), | ||
nextRun7 = scheduler7.next(); | ||
}).should.not.throw(); | ||
}); | ||
it("Weekday 0 (sunday) and weekday 7 (sunday) should give the same run time", function () { | ||
var | ||
scheduler0 = new Cron("0 0 0 * * 0"), | ||
scheduler7 = new Cron("0 0 0 * * 7"), | ||
nextRun0 = scheduler0.next(), | ||
nextRun7 = scheduler7.next(); | ||
nextRun0.getTime().should.equal(nextRun7.getTime()); | ||
}); | ||
}); | ||
@@ -450,0 +478,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41633
10
888