Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

croner

Package Overview
Dependencies
Maintainers
1
Versions
228
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

croner - npm Package Compare versions

Comparing version 1.1.19 to 1.1.20

37

lib/croner.js
/* ------------------------------------------------------------------------------------
Croner - MIT License - Hexagon <github.com/Hexagon>
Croner 1.1.20 - MIT License - Hexagon <github.com/Hexagon>

@@ -57,14 +57,2 @@ Pure JavaScript Isomorphic cron parser and scheduler without dependencies.

function safeDate() {
// Create new date object
var d = new Date();
// Make sure milliseconds is 0. Else we will get unwanted behaviour at comparisons
d.setMilliseconds(0);
// Return the "safe" date
return d;
}
function fill(arr, val) {

@@ -88,2 +76,3 @@

function CronDate (date) {
this.milliseconds = date.getMilliseconds();
this.seconds = date.getSeconds() + 1;

@@ -175,3 +164,3 @@ this.minutes = date.getMinutes();

CronDate.prototype.getDate = function () {
return new Date(this.years, this.months, this.days, this.hours, this.minutes, this.seconds, 0);
return new Date(this.years, this.months, this.days, this.hours, this.minutes, this.seconds, 500);
};

@@ -407,5 +396,13 @@

// "Exposed" version of next strips milliseconds
Cron.prototype.next = function (prev) {
var dirtyDate = this._next(prev);
if (dirtyDate) dirtyDate.setMilliseconds(0);
return dirtyDate;
}
// Cron needs millseconds internally, hence _next
Cron.prototype._next = function (prev) {
prev = prev || safeDate();
prev = prev || new Date();

@@ -465,6 +462,6 @@ // Previous run should never be before startAt

Cron.prototype.msToNext = function (prev) {
prev = prev || safeDate();
var next = this.next(prev);
prev = prev || new Date();
var next = this._next(prev);
if( next ) {
return (this.next(prev) - prev.getTime());
return (this._next(prev) - prev.getTime());
} else {

@@ -520,3 +517,3 @@ return next;

opts.maxRuns--;
opts.previous = safeDate();
opts.previous = new Date();
func();

@@ -527,3 +524,3 @@ }

if( opts.paused ) {
opts.previous = safeDate();
opts.previous = new Date();
}

@@ -530,0 +527,0 @@

@@ -1,2 +0,2 @@

// 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||{}),void 0===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&&this.pattern.constructor!==String&&c("Pattern has to be of type string.");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){if(a=a||d(),this.opts.startAt&&a<this.opts.startAt&&(a=this.opts.startAt),!(this.opts.maxRuns<=0||this.opts.kill)){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 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.")),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=void 0!==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),void 0!==f)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);
// Licenced under MIT - croner 1.1.20 - ©2016 Hexagon <github.com/hexagon>
(function(){"use strict";function t(t){throw new TypeError("Cron parser: "+t)}function e(t,e){for(var s=0;s<t.length;s++)t[s]=e;return t}function s(t){this.milliseconds=t.getMilliseconds(),this.seconds=t.getSeconds()+1,this.minutes=t.getMinutes(),this.hours=t.getHours(),this.days=t.getDate(),this.months=t.getMonth(),this.years=t.getFullYear()}function r(t){this.pattern=t,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 a(t,e,s){var n=this;return this instanceof a?(n.pattern=new r(t),n.schedulerDefaults={stopAt:1/0,maxRuns:1/0,kill:!1},"function"==typeof e&&(s=e,e={}),n.opts=n.validateOpts(e||{}),void 0===s?n:this.schedule(e,s)):new a(t,e,s)}var n=this,i=Math.pow(2,31)-1;s.prototype.increment=function(t){for(var e=this,s=function(t,s,r,a){for(var n=void 0===a?e[t]+r:0+r;n<s[t].length;n++)if(s[t][n])return e[t]=n-r,!0;return!1},r=[["seconds","minutes",0],["minutes","hours",0],["hours","days",0],["days","months",-1],["months","years",0]],a=0;a<5;){if(!s(r[a][0],t,r[a][2]))for(this[r[a][1]]++;a>=0;)s(r[a][0],t,r[a][2],0),a--;a++}for(;!t.daysOfWeek[this.getDate().getDay()];)this.days+=1},s.prototype.getDate=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,500)},r.prototype.parse=function(){"string"!=typeof this.pattern&&this.pattern.constructor!==String&&t("Pattern has to be of type string.");var e,s,r,a,n,i=this.pattern.trim().replace(/\s+/g," ").split(" "),o=/[^\/\*0-9,-]+/;for(6!==i.length&&t("invalid configuration format ('"+this.pattern+"'), exacly five space separated parts required."),s=0;s<i.length;s++)e=i[s].trim(),o.test(e)&&t("configuration entry "+(s+1)+" ("+e+") contains illegal characters.");r="*"!==i[4],a="*"!==i[5],n="*"!==i[3],a&&(r||n)&&t("configuration invalid, you can not combine month/date with day of week."),this.partToArray("seconds",i[0],0),this.partToArray("minutes",i[1],0),this.partToArray("hours",i[2],0),this.partToArray("days",i[3],-1),this.partToArray("months",i[4],-1),this.partToArray("daysOfWeek",i[5],0),this.daysOfWeek[7]&&(this.daysOfWeek[0]=1)},r.prototype.partToArray=function(e,s,r){var a,n,i,o,u,p=this[e];if("*"!==s)if((n=s.split(",")).length>1)for(a=0;a<n.length;a++)this.partToArray(e,n[a],r);else if(-1!==s.indexOf("-"))for(2!==(n=s.split("-")).length&&t("Syntax error, illegal range: '"+s+"'"),i=parseInt(n[0],10)+r,o=parseInt(n[1],10)+r,isNaN(i)?t("Syntax error, illegal lower range (NaN)"):isNaN(o)&&t("Syntax error, illegal upper range (NaN)"),(i<0||o>=p.length)&&t("Value out of range: '"+s+"'"),i>o&&t("From value is larger than to value: '"+s+"'"),a=i;a<=o;a++)p[a+r]=1;else if(-1!==s.indexOf("/"))for(2!==(n=s.split("/")).length&&t("Syntax error, illegal stepping: '"+s+"'"),"*"!==n[0]&&t("Syntax error, left part of / needs to be * : '"+s+"'"),u=parseInt(n[1],10),isNaN(u)&&t("Syntax error, illegal stepping: (NaN)"),0===u&&t("Syntax error, illegal stepping: 0"),u>p.length&&t("Syntax error, steps cannot be greater than maximum value of part ("+p.length+")"),a=0;a<p.length;a+=u)p[a+r]=1;else((a=parseInt(s,10)+r)<0||a>=p.length)&&t(e+" value out of range: '"+s+"'"),p[a]=1;else for(a=0;a<p.length;a++)p[a]=1},a.prototype.next=function(t){var e=this._next(t);return e&&e.setMilliseconds(0),e},a.prototype._next=function(t){if(t=t||new Date,this.opts.startAt&&t<this.opts.startAt&&(t=this.opts.startAt),!(this.opts.maxRuns<=0||this.opts.kill)){var e,r=this.opts.stopAt||this.schedulerDefaults.stopAt,a=new s(t);return a.increment(this.pattern),e=a.getDate(),r&&e>=r?void 0:e}},a.prototype.validateOpts=function(e){return e.startAt&&(e.startAt.constructor!==Date?e.startAt=new Date(Date.parse(e.startAt)-1):e.startAt=new Date(e.startAt.getTime()-1),isNaN(e.startAt)&&t("Provided value for startAt could not be parsed as date.")),e.stopAt&&(e.stopAt.constructor!==Date&&(e.stopAt=new Date(Date.parse(e.stopAt))),isNaN(e.stopAt)&&t("Provided value for stopAt could not be parsed as date.")),e},a.prototype.msToNext=function(t){t=t||new Date;var e=this._next(t);return e?this._next(t)-t.getTime():e},a.prototype.schedule=function(t,e){var s,r=this,a=r.maxDelay||i;if(e||(e=t,t={}),t.paused=void 0!==t.paused&&t.paused,t.kill=t.kill||this.schedulerDefaults.kill,t.rest=t.rest||0,t.maxRuns||0===t.maxRuns||(t.maxRuns=this.schedulerDefaults.maxRuns),r.opts=r.validateOpts(t||{}),void 0!==(s=this.msToNext(t.previous)))return s>a&&(s=a),t.currentTimeout=setTimeout(function(){s===a||t.paused||(t.maxRuns--,t.previous=new Date,e()),t.paused&&(t.previous=new Date),r.schedule(t,e)},s),{stop:function(){t.kill=!0,t.currentTimeout&&clearTimeout(t.currentTimeout)},pause:function(){return(t.paused=!0)&&!t.kill},resume:function(){return!(t.paused=!1)&&!t.kill}}},"undefined"!=typeof module&&"object"==typeof module.exports?module.exports=a:"function"==typeof define&&define.amd?define([],function(){return a}):n.Cron=a}).call(this);
{
"name": "croner",
"version": "1.1.19",
"version": "1.1.20",
"description": "Isomorphic JavaScript cron parser and scheduler.",

@@ -13,2 +13,4 @@ "author": "Hexagon <github.com/hexagon>",

},
"main": "index.js",
"browser": "./lib/croner.min.js",
"repository": {

@@ -15,0 +17,0 @@ "type": "git",

@@ -213,4 +213,4 @@

```
┌──────────────── sec (0 - 59)
│ ┌────────────── min (0 - 59)
┌──────────────── second (0 - 59)
│ ┌────────────── minute (0 - 59)
│ │ ┌──────────── hour (0 - 23)

@@ -217,0 +217,0 @@ │ │ │ ┌────────── day of month (1 - 31)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc