Socket
Socket
Sign inDemoInstall

cron

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cron - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

.eslintrc

249

lib/cron.js

@@ -1,13 +0,23 @@

(function (root, factory) {
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['moment-timezone'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('moment-timezone'), require('child_process'));
module.exports = factory(
require('moment-timezone'),
require('child_process')
);
} else {
root.Cron = factory(root.moment);
}
}(this, function (moment, child_process) {
var exports = {},
timeUnits = ['second', 'minute', 'hour', 'dayOfMonth', 'month', 'dayOfWeek'],
spawn = child_process && child_process.spawn;
})(this, function(moment, childProcess) {
var exports = {};
var timeUnits = [
'second',
'minute',
'hour',
'dayOfMonth',
'month',
'dayOfWeek'
];
var spawn = childProcess && childProcess.spawn;

@@ -28,7 +38,7 @@ function CronTime(source, zone, utcOffset) {

var that = this;
timeUnits.map(function(timeUnit){
timeUnits.map(function(timeUnit) {
that[timeUnit] = {};
});
if (this.source instanceof Date || this.source._isAMomentObject) {
if (this.source instanceof Date || this.source._isAMomentObject) {
this.source = moment(this.source);

@@ -42,13 +52,6 @@ this.realDate = true;

CronTime.constraints = [
[0, 59],
[0, 59],
[0, 23],
[1, 31],
[0, 11],
[0, 6]
];
CronTime.constraints = [[0, 59], [0, 59], [0, 23], [1, 31], [0, 11], [0, 6]];
CronTime.monthConstraints = [
31,
29, //support leap year...not perfect
29, // support leap year...not perfect
31,

@@ -88,3 +91,2 @@ 30,

CronTime.prototype = {

@@ -102,8 +104,12 @@ _verifyParse: function() {

var dom = dsom[j];
if (dom <= con)
if (dom <= con) {
ok = true;
} else {
delete this.dayOfMonth[j];
this.dayOfMonth[String(Number(dsom[j])) % con] = true;
}
}
if (!ok) {
console.warn('Month \'' + m + '\' is limited to \'' + con + '\' days.');
console.warn("Month '" + m + "' is limited to '" + con + "' days.");
}

@@ -131,7 +137,3 @@ }

var now = new Date();
var targetSecond = date.seconds();
var diff = Math.abs(targetSecond - now.getSeconds())
//If the i argument is not given, return the next send time
// If the i argument is not given, return the next send time
if (isNaN(i) || i < 0) {

@@ -142,3 +144,3 @@ date = this._getNextDateFrom(date);

} else {
//Else return the next i send times
// Else return the next i send times
var dates = [];

@@ -148,3 +150,2 @@ for (; i > 0; i--) {

dates.push(moment(date));
}

@@ -184,26 +185,27 @@

_getNextDateFrom: function(start,zone) {
_getNextDateFrom: function(start, zone) {
var date;
var firstDate=moment(start).valueOf();
if(zone){
date=moment(start).tz(zone);
var firstDate = moment(start).valueOf();
if (zone) {
date = moment(start).tz(zone);
} else {
date = moment(start);
}
else{
date = moment(start);
}
if (!this.realDate) {
const milliseconds = (start.milliseconds && start.milliseconds()) || (start.getMilliseconds && start.getMilliseconds()) || 0;
if (milliseconds > 0) {
date.milliseconds(0);
date.seconds(date.seconds() + 1);
}
const milliseconds =
(start.milliseconds && start.milliseconds()) ||
(start.getMilliseconds && start.getMilliseconds()) ||
0;
if (milliseconds > 0) {
date.milliseconds(0);
date.seconds(date.seconds() + 1);
}
}
if (date.toString() == 'Invalid date') {
console.log('ERROR: You specified an invalid date.');
return date;
if (date.toString() === 'Invalid date') {
throw new Error('ERROR: You specified an invalid date.');
}
if (this.realDate && start < new Date()) {
console.log('WARNING: Date in past. Will never be fired.');
throw new Error('WARNING: Date in past. Will never be fired.');
}

@@ -215,8 +217,11 @@

//sanity check
// sanity check
while (true) {
var diff = date - start,
origDate = new Date(date);
var diff = date - start;
var origDate = new Date(date);
if (!(date.month() in this.month) && Object.keys(this.month).length!=12) {
if (
!(date.month() in this.month) &&
Object.keys(this.month).length !== 12
) {
date.add(1, 'M');

@@ -229,3 +234,6 @@ date.date(1);

}
if (!(date.date() in this.dayOfMonth) && Object.keys(this.dayOfMonth).length!=31) {
if (
!(date.date() in this.dayOfMonth) &&
Object.keys(this.dayOfMonth).length !== 31
) {
date.add(1, 'd');

@@ -238,3 +246,6 @@ date.hours(0);

if (!(date.day() in this.dayOfWeek) && Object.keys(this.dayOfWeek).length!=7) {
if (
!(date.day() in this.dayOfWeek) &&
Object.keys(this.dayOfWeek).length !== 7
) {
date.add(1, 'd');

@@ -249,5 +260,10 @@ date.hours(0);

}
if (!(date.hours() in this.hour) && Object.keys(this.hour).length!=24) {
if (
!(date.hours() in this.hour) &&
Object.keys(this.hour).length !== 24
) {
origDate = moment(date);
date.hours(date.hours() == 23 && diff > 86400000 ? 0 : date.hours() + 1);
date.hours(
date.hours() == 23 && diff > 86400000 ? 0 : date.hours() + 1
);
date.minutes(0);

@@ -260,5 +276,12 @@ date.seconds(0);

}
if (!(date.minutes() in this.minute) && Object.keys(this.minute).length!=60) {
if (
!(date.minutes() in this.minute) &&
Object.keys(this.minute).length !== 60
) {
origDate = moment(date);
date.minutes(date.minutes() == 59 && diff > 60 * 60 * 1000 ? 0 : date.minutes() + 1);
date.minutes(
date.minutes() === 59 && diff > 60 * 60 * 1000
? 0
: date.minutes() + 1
);
date.seconds(0);

@@ -270,5 +293,10 @@ if (date <= origDate) {

}
if (!(date.seconds() in this.second) && Object.keys(this.second).length!=60) {
if (
!(date.seconds() in this.second) &&
Object.keys(this.second).length !== 60
) {
origDate = moment(date);
date.seconds(date.seconds() == 59 && diff > 60 * 1000 ? 0 : date.seconds() + 1);
date.seconds(
date.seconds() === 59 && diff > 60 * 1000 ? 0 : date.seconds() + 1
);
if (date <= origDate) {

@@ -280,4 +308,4 @@ date = this._findDST(origDate);

if(date.valueOf() === firstDate){
date.seconds(date.seconds()+1);
if (date.valueOf() === firstDate) {
date.seconds(date.seconds() + 1);
continue;

@@ -297,4 +325,5 @@ }

var newDate = moment(date);
while (newDate <= date)
while (newDate <= date) { // eslint seems to trigger here, it is wrong
newDate.add(1, 's');
}

@@ -322,4 +351,3 @@ return newDate;

for (var i = constrain[0], n = constrain[1]; i < n; i++) {
if (!(i in this[type]))
return false;
if (!(i in this[type])) return false;
}

@@ -330,6 +358,5 @@

_parse: function() {
var aliases = CronTime.aliases;
var source = this.source.replace(/[a-z]{1,3}/ig, function(alias) {
var source = this.source.replace(/[a-z]{1,3}/gi, function(alias) {
alias = alias.toLowerCase();

@@ -367,3 +394,3 @@

//commas separate information, so split based on those
// commas separate information, so split based on those
var allRanges = field.split(',');

@@ -385,3 +412,3 @@

do {
typeObj[pointer] = true
typeObj[pointer] = true;
pointer += step;

@@ -420,6 +447,16 @@ } while (pointer <= upper);

return cmd
return cmd;
}
function CronJob(cronTime, onTick, onComplete, startNow, timeZone, context, runOnInit, utcOffset) {
function CronJob(
cronTime,
onTick,
onComplete,
startNow,
timeZone,
context,
runOnInit,
utcOffset,
unrefTimeout
) {
var _cronTime = cronTime;

@@ -432,4 +469,4 @@ var argCount = 0;

}
if (typeof cronTime != 'string' && argCount == 1) {
//crontime is an object...
if (typeof cronTime !== 'string' && argCount === 1) {
// crontime is an object...
onTick = cronTime.onTick;

@@ -443,8 +480,10 @@ onComplete = cronTime.onComplete;

utcOffset = cronTime.utcOffset;
unrefTimeout = cronTime.unrefTimeout;
}
this.context = (context || this);
this.context = context || this;
this._callbacks = [];
this.onComplete = command2function(onComplete);
this.cronTime = new CronTime(_cronTime, timeZone, utcOffset);
this.unrefTimeout = unrefTimeout;

@@ -466,20 +505,21 @@ addCallback.call(this, command2function(onTick));

var addCallback = function(callback) {
if (typeof callback == 'function') this._callbacks.push(callback);
}
if (typeof callback === 'function') this._callbacks.push(callback);
};
CronJob.prototype.addCallback = addCallback;
CronJob.prototype.setTime = function(time) {
if (!(time instanceof CronTime)) throw new Error('\'time\' must be an instance of CronTime.');
if (!(time instanceof CronTime))
throw new Error('time must be an instance of CronTime.');
this.stop();
this.cronTime = time;
}
};
CronJob.prototype.nextDate = function() {
return this.cronTime.sendAt();
}
};
var fireOnTick = function() {
for (var i = (this._callbacks.length - 1); i >= 0; i--)
for (var i = this._callbacks.length - 1; i >= 0; i--)
this._callbacks[i].call(this.context, this.onComplete);
}
};
CronJob.prototype.fireOnTick = fireOnTick;

@@ -489,3 +529,3 @@

return this.cronTime.sendAt(i);
}
};

@@ -506,2 +546,5 @@ var start = function() {

self._timeout = setTimeout(callbackWrapper, timeout);
if (self.unrefTimeout && typeof self._timeout.unref === 'function') {
self._timeout.unref();
}
}

@@ -542,3 +585,2 @@

} else {
// We have arrived at the correct point in time.

@@ -548,8 +590,6 @@

//start before calling back so the callbacks have the ability to stop the cron job
if (!(self.runOnce)) self.start();
// start before calling back so the callbacks have the ability to stop the cron job
if (!self.runOnce) self.start();
self.fireOnTick();
//for (var i = (self._callbacks.length - 1); i >= 0; i--)
//self._callbacks[i].call(self.context, self.onComplete);
}

@@ -572,7 +612,7 @@ }

}
}
};
CronJob.prototype.start = start;
CronJob.prototype.lastDate = function(){
CronJob.prototype.lastDate = function() {
return this.lastExecution;

@@ -585,23 +625,42 @@ };

CronJob.prototype.stop = function() {
if (this._timeout)
clearTimeout(this._timeout);
if (this._timeout) clearTimeout(this._timeout);
this.running = false;
if (typeof this.onComplete == 'function') this.onComplete();
}
if (typeof this.onComplete === 'function') this.onComplete();
};
exports.job = function(cronTime, onTick, onComplete, startNow, timeZone, context, runOnInit, utcOffset) {
return new CronJob(cronTime, onTick, onComplete, startNow, timeZone, context, runOnInit, utcOffset);
}
exports.job = function(
cronTime,
onTick,
onComplete,
startNow,
timeZone,
context,
runOnInit,
utcOffset,
unrefTimeout
) {
return new CronJob(
cronTime,
onTick,
onComplete,
startNow,
timeZone,
context,
runOnInit,
utcOffset,
unrefTimeout
);
};
exports.time = function(cronTime, timeZone) {
return new CronTime(cronTime, timeZone);
}
};
exports.sendAt = function(cronTime) {
return exports.time(cronTime).sendAt();
}
};
exports.timeout = function(cronTime) {
return exports.time(cronTime).getTimeout();
}
};

@@ -612,2 +671,2 @@ exports.CronJob = CronJob;

return exports;
}));
});
{
"name": "cron",
"description": "Cron jobs for your node",
"version": "1.3.1",
"version": "1.4.0",
"author": "Nick Campbell <nicholas.j.campbell@gmail.com> (http://github.com/ncb000gt)",

@@ -23,4 +23,22 @@ "bugs": {

"chai": "~4.1.x",
"sinon": "~1.12.x"
"sinon": "~1.12.x",
"eslint": "~5.3.x",
"eslint-config-prettier": "~3.0.x",
"eslint-config-standard": "~11.0.x",
"eslint-plugin-import": "~2.14.x",
"eslint-plugin-node": "~7.0.x",
"eslint-plugin-prettier": "~2.6.x",
"eslint-plugin-promise": "~3.8.x",
"eslint-plugin-standard": "~3.1.x",
"prettier": "~1.14.x"
},
"keywords": [
"cron",
"node cron",
"node-cron",
"schedule",
"scheduler",
"cronjob",
"cron job"
],
"license": "MIT",

@@ -27,0 +45,0 @@ "contributors": [

node-cron
=========
=
[![Build Status](https://travis-ci.org/kelektiv/node-cron.svg?branch=master)](https://travis-ci.org/#!/kelektiv/node-cron)
[![wercker status](https://app.wercker.com/status/0cadfe5d45ad7bc819efb636026cf230/s "wercker status")](https://app.wercker.com/project/bykey/0cadfe5d45ad7bc819efb636026cf230)
[![Dependency Status](https://david-dm.org/ncb000gt/node-cron.svg)](https://david-dm.org/ncb000gt/node-cron)
Originally this project was a NodeJS fork of [James Padolsey's][jamespadolsey] [cron.js](http://github.com/padolsey/cron.js).
Cron is a tool that allows you to execute _something_ on a schedule. This is
typically done using the cron syntax. We allow you to execute a function
whenever your scheduled job triggers. We also allow you to execute a job
external to the javascript process using `child_process`. Additionally, this
library goes beyond the basic cron syntax and allows you to
supply a Date object. This will be used as the trigger for your callback. Cron
syntax is still an acceptable CronTime format. Although the Cron patterns
supported here extend on the standard Unix format to support seconds digits,
leaving it off will default to 0 and match the Unix behavior.
After [Craig Condon][crcn] made some updates and changes to the code base this has evolved to something that has a bit of both. The cron syntax parsing is mostly James' while using timeout instead of interval is Craig's.
Additionally, this library goes beyond the basic cron syntax and allows you to supply a Date object. This will be used as the trigger for your callback. Cron syntax is still an acceptable CronTime format. Although the Cron patterns supported here extend on the standard Unix format to support seconds digits, leaving it off will default to 0 and match the Unix behavior.
Installation
==
There are tools that help when constructing your cronjobs. You might find
something like https://cronjob.xyz/ helpful. But, note that it doesn't accept
the exact same syntax as this library, for instance, it doesn't accept the
`seconds` field, so keep that in mind.
npm install cron
If You Are Submitting Bugs/Issues
=============
==
Because we can't magically know what you are doing to expose an issue, it is best if you provide a snippet of code. This snippet need not include your secret sauce, but it must replicate the issue you are describing. The issues that get closed without resolution tend to be the ones without code examples. Thanks.
Because we can't magically know what you are doing to expose an issue, it is
best if you provide a snippet of code. This snippet need not include your secret
sauce, but it must replicate the issue you are describing. The issues that get
closed without resolution tend to be the ones without code examples. Thanks.
Versions and Backwards compatibility breaks:
==========
==
As goes with semver, breaking backwards compatibility should be explicit in the versioning of your library. As such, we'll upgrade the version of this module in accordance with breaking changes (I'm not always great about doing it this way so if you notice that there are breaking changes that haven't been bumped appropriately please let me know). This table lists out the issues which were the reason for the break in backward compatibility.
As goes with semver, breaking backwards compatibility should be explicit in the
versioning of your library. As such, we'll upgrade the version of this module
in accordance with breaking changes (I'm not always great about doing it this
way so if you notice that there are breaking changes that haven't been bumped
appropriately please let me know).
<table>
<tr>
<td>Node Cron Ver</td><td>Issue #</td>
</tr>
<tr>
<td>1.0.0</td><td><ul><li><a href="https://github.com/ncb000gt/node-cron/pull/41">GH-41</a></li><li><a href="https://github.com/ncb000gt/node-cron/pull/36">GH-36</a></li></ul></td>
</tr>
</table>
Usage (basic cron usage):
==========
==

@@ -51,6 +53,11 @@ ```javascript

Note - You need to explictly start a job in order to make it run. This gives a little more control over running your jobs.
Note - You need to explictly start a job in order to make it run. This gives a
little more control over running your jobs.
There are more examples available in this repository at:
[/examples](https://github.com/kelektiv/node-cron/tree/master/examples)
Available Cron patterns:
==========
==

@@ -65,6 +72,14 @@ Asterisk. E.g. *

There are tools that help when constructing your cronjobs. You might find
something like https://cronjob.xyz/ helpful. But, note that it doesn't accept
the exact same syntax as this library, for instance, it doesn't accept the
`seconds` field, so keep that in mind.
Cron Ranges
==========
==
When specifying your cron values you'll need to make sure that your values fall within the ranges. For instance, some cron's use a 0-7 range for the day of week where both 0 and 7 represent Sunday. We do not.
When specifying your cron values you'll need to make sure that your values fall
within the ranges. For instance, some cron's use a 0-7 range for the day of
week where both 0 and 7 represent Sunday. We do not.

@@ -79,137 +94,4 @@ * Seconds: 0-59

Another cron example
==========
```javascript
var CronJob = require('cron').CronJob;
var job = new CronJob('00 30 11 * * 1-5', function() {
/*
* Runs every weekday (Monday through Friday)
* at 11:30:00 AM. It does not run on Saturday
* or Sunday.
*/
}, function () {
/* This function is executed when the job stops */
},
true, /* Start the job right now */
timeZone /* Time zone of this job. */
);
```
Another example with Date
==========
```javascript
var CronJob = require('cron').CronJob;
var job = new CronJob(new Date(), function() {
/* runs once at the specified date. */
}, function () {
/* This function is executed when the job stops */
},
true, /* Start the job right now */
timeZone /* Time zone of this job. */
);
```
For good measure
==========
```javascript
var CronJob = require('cron').CronJob;
var job = new CronJob({
cronTime: '00 30 11 * * 1-5',
onTick: function() {
/*
* Runs every weekday (Monday through Friday)
* at 11:30:00 AM. It does not run on Saturday
* or Sunday.
*/
},
start: false,
timeZone: 'America/Los_Angeles'
});
job.start();
```
Running a job every 5 minutes
==========
```javascript
var CronJob = require('cron').CronJob;
var job = new CronJob({
cronTime: '00 */5 * * * *',
onTick: function() {
/*
* Runs every weekday (Monday through Friday)
* at 11:30:00 AM. It does not run on Saturday
* or Sunday.
*/
},
start: false,
timeZone: 'America/Los_Angeles'
});
job.start();
```
How to check if a cron pattern is valid:
==========
```javascript
try {
new CronJob('invalid cron pattern', function() {
console.log('this should not be printed');
})
} catch(ex) {
console.log("cron pattern not valid");
}
```
How to check if a job is running
==========
```javascript
var cron = require('cron');
var job1 = new cron.CronJob({
cronTime: '* * * * *',
onTick: function() {
console.log('job 1 ticked');
},
start: false,
timeZone: 'America/Los_Angeles'
});
var job2 = new cron.CronJob({
cronTime: '* * * * *',
onTick: function() {
console.log('job 2 ticked');
},
start: false,
timeZone: 'America/Los_Angeles'
});
console.log('job1 status', job1.running); // job1 status undefined
console.log('job2 status', job2.running); // job2 status undefined
job1.start(); // job 1 started
console.log('job1 status', job1.running); // job1 status true
console.log('job2 status', job2.running); // job2 status undefined
```
Install
==========
From source: `npm install`
From npm: `npm install cron`
API
==========
==

@@ -223,14 +105,42 @@ Parameter Based

* `CronJob`
* `constructor(cronTime, onTick, onComplete, start, timezone, context, runOnInit)` - Of note, the first parameter here can be a JSON object that has the below names and associated types (see examples above).
* `cronTime` - [REQUIRED] - The time to fire off your job. This can be in the form of cron syntax or a JS [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.
* `onTick` - [REQUIRED] - The function to fire at the specified time. If an `onComplete` callback was provided, `onTick` will receive it as an argument. `onTick` may call `onComplete` when it has finished its work.
* `onComplete` - [OPTIONAL] - A function that will fire when the job is stopped with `job.stop()`, and may also be called by `onTick` at the end of each run.
* `start` - [OPTIONAL] - Specifies whether to start the job just before exiting the constructor. By default this is set to false. If left at default you will need to call `job.start()` in order to start the job (assuming `job` is the variable you set the cronjob to). This does not immediately fire your `onTick` function, it just gives you more control over the behavior of your jobs.
* `timeZone` - [OPTIONAL] - Specify the timezone for the execution. This will modify the actual time relative to your timezone. If the timezone is invalid, an error is thrown. You can check all timezones available at [Moment Timezone Website](http://momentjs.com/timezone/). Probably don't use both
* `constructor(cronTime, onTick, onComplete, start, timezone, context,
runOnInit, unrefTimeout)` - Of note, the first parameter here can be a JSON object that
has the below names and associated types (see examples above).
* `cronTime` - [REQUIRED] - The time to fire off your job. This can be in
the form of cron syntax or a JS
[Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.
* `onTick` - [REQUIRED] - The function to fire at the specified time. If an
`onComplete` callback was provided, `onTick` will receive it as an argument.
`onTick` may call `onComplete` when it has finished its work.
* `onComplete` - [OPTIONAL] - A function that will fire when the job is
stopped with `job.stop()`, and may also be called by `onTick` at the end of each run.
* `start` - [OPTIONAL] - Specifies whether to start the job just before
exiting the constructor. By default this is set to false. If left at default
you will need to call `job.start()` in order to start the job (assuming
`job` is the variable you set the cronjob to). This does not immediately
fire your `onTick` function, it just gives you more control over the
behavior of your jobs.
* `timeZone` - [OPTIONAL] - Specify the timezone for the execution. This
will modify the actual time relative to your timezone. If the timezone is
invalid, an error is thrown. You can check all timezones available at
[Moment Timezone Website](http://momentjs.com/timezone/). Probably don't use
both.
`timeZone` and `utcOffset` together or weird things may happen.
* `context` - [OPTIONAL] - The context within which to execute the onTick method. This defaults to the cronjob itself allowing you to call `this.stop()`. However, if you change this you'll have access to the functions and values within your context object.
* `runOnInit` - [OPTIONAL] - This will immediately fire your `onTick` function as soon as the requisit initialization has happened. This option is set to `false` by default for backwards compatibility.
* `context` - [OPTIONAL] - The context within which to execute the onTick
method. This defaults to the cronjob itself allowing you to call
`this.stop()`. However, if you change this you'll have access to the
functions and values within your context object.
* `runOnInit` - [OPTIONAL] - This will immediately fire your `onTick`
function as soon as the requisite initialization has happened. This option
is set to `false` by default for backwards compatibility.
* `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your
timezone rather than using the `timeZone` param. Probably don't use both
`timeZone` and `utcOffset` together or weird things may happen.
* `unrefTimeout` - [OPTIONAL] - If you have code that keeps the event loop
running and want to stop the node process when that finishes regardless of
the state of your cronjob, you can do so making use of this parameter. This
is off by default and cron will run as if it needs to control the event
loop. For more information take a look at
[timers#timers_timeout_unref](https://nodejs.org/api/timers.html#timers_timeout_unref)
from the NodeJS docs.
* `start` - Runs your job.

@@ -241,35 +151,26 @@ * `stop` - Stops your job.

* `nextDates` - Provides an array of the next set of dates that will trigger an `onTick`.
* `fireOnTick` - Allows you to override the `onTick` calling behavior. This matters so only do this if you have a really good reason to do so.
* `fireOnTick` - Allows you to override the `onTick` calling behavior. This
matters so only do this if you have a really good reason to do so.
* `addCallback` - Allows you to add `onTick` callbacks.
* `CronTime`
* `constructor(time)`
* `time` - [REQUIRED] - The time to fire off your job. This can be in the form of cron syntax or a JS [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.
* `time` - [REQUIRED] - The time to fire off your job. This can be in the
form of cron syntax or a JS
[Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date)
object.
Contributors
===========
* [Romain Beauxis][toots]
* [James Padolsey][jamespadolsey]
* [Craig Condon][crcn]
* [Finn Herpich][errorprone]
* [cliftonc][cliftonc]
* [neyric][neyric]
* [humanchimp][humanchimp]
* [danhbear][danhbear]
* [Jordan Abderrachid][jordanabderrachid]
Contributions
==
This is a community effort project. In the truest sense, this project started as
an open source project from [cron.js](http://github.com/padolsey/cron.js) and
grew into something else. Other people have contributed code, time, and
oversight to the project. At this point there are too many to name here so I'll
just say thanks.
License
==========
==
MIT
[toots]:http://github.com/toots
[jamespadolsey]:http://github.com/padolsey
[crcn]:http://github.com/crcn
[cliftonc]:http://github.com/cliftonc
[neyric]:http://github.com/neyric
[humanchimp]:http://github.com/humanchimp
[errorprone]:http://github.com/ErrorProne
[danhbear]:http://github.com/danhbear
[jordanabderrachid]:http://github.com/jordanabderrachid

@@ -1,5 +0,5 @@

var chai = require('chai'),
expect = chai.expect,
sinon = require('sinon'),
cron = require('../lib/cron');
var chai = require('chai');
var expect = chai.expect;
var sinon = require('sinon');
var cron = require('../lib/cron');

@@ -11,5 +11,10 @@ describe('cron', function() {

var job = new cron.CronJob('* * * * * *', function() {
c++;
}, null, true);
var job = new cron.CronJob(
'* * * * * *',
function() {
c++;
},
null,
true
);

@@ -27,8 +32,13 @@ clock.tick(1000);

var job = new cron.CronJob('* * * * * *', function() {
c++;
}, function () {
expect(c).to.eql(1);
done();
}, true);
var job = new cron.CronJob(
'* * * * * *',
function() {
c++;
},
function() {
expect(c).to.eql(1);
done();
},
true
);

@@ -40,13 +50,18 @@ clock.tick(1000);

it('should fire every 60 min', function () {
it('should fire every 60 min', function() {
var m60 = 60 * 60 * 1000;
var clock = sinon.useFakeTimers();
var l = [];
var job = new cron.CronJob('00 30 * * * *', function () {
l.push(Math.floor(Date.now() / 60000));
},null,true);
var clock = sinon.useFakeTimers();
var l = [];
var job = new cron.CronJob(
'00 30 * * * *',
function() {
l.push(Math.floor(Date.now() / 60000));
},
null,
true
);
clock.tick(m60 * 10);
expect(l.length).to.eql(10);
expect(l.length).to.eql(10);
for (var i = 0; i < l.length; i++) {

@@ -58,3 +73,3 @@ expect(l[i] % 30).to.eql(0);

clock.restore();
});
});

@@ -65,9 +80,14 @@ it('should use standard cron no-seconds syntax (* * * * *)', function() {

var job = new cron.CronJob('* * * * *', function() {
c++;
}, null, true);
var job = new cron.CronJob(
'* * * * *',
function() {
c++;
},
null,
true
);
clock.tick(1000); //tick second
clock.tick(1000); // tick second
clock.tick(59 * 1000); //tick minute
clock.tick(59 * 1000); // tick minute

@@ -84,8 +104,12 @@ job.stop();

var job = new cron.CronJob('* * * * * *', function() {
c++;
}, null, true);
var job = new cron.CronJob(
'* * * * * *',
function() {
c++;
},
null,
true
);
for (var i = 0; i < 5; i++)
clock.tick(1000);
for (var i = 0; i < 5; i++) clock.tick(1000);

@@ -102,11 +126,15 @@ clock.restore();

var job = new cron.CronJob('* * * * * *', function() {
c++;
}, function() {
expect(c).to.eql(5);
done();
}, true);
var job = new cron.CronJob(
'* * * * * *',
function() {
c++;
},
function() {
expect(c).to.eql(5);
done();
},
true
);
for (var i = 0; i < 5; i++)
clock.tick(1000);
for (var i = 0; i < 5; i++) clock.tick(1000);

@@ -121,8 +149,12 @@ clock.restore();

var job = new cron.CronJob('*/1 * * * * *', function() {
c++;
}, null, true);
var job = new cron.CronJob(
'*/1 * * * * *',
function() {
c++;
},
null,
true
);
for (var i = 0; i < 5; i++)
clock.tick(1000);
for (var i = 0; i < 5; i++) clock.tick(1000);

@@ -134,3 +166,3 @@ clock.restore();

//ensure that this is running on the second second
// ensure that this is running on the second second
it('should run every 2 seconds for 1 seconds (*/2 * * * * *)', function() {

@@ -140,5 +172,10 @@ var clock = sinon.useFakeTimers();

var job = new cron.CronJob('*/2 * * * * *', function() {
c++;
}, null, true);
var job = new cron.CronJob(
'*/2 * * * * *',
function() {
c++;
},
null,
true
);

@@ -156,8 +193,12 @@ clock.tick(1000);

var job = new cron.CronJob('*/2 * * * * *', function() {
c++;
}, null, true);
var job = new cron.CronJob(
'*/2 * * * * *',
function() {
c++;
},
null,
true
);
for (var i = 0; i < 5; i++)
clock.tick(1000);
for (var i = 0; i < 5; i++) clock.tick(1000);

@@ -173,11 +214,15 @@ clock.restore();

var job = new cron.CronJob('*/1 * * * * *', function() {
c++
}, function() {
expect(c).to.eql(5);
done();
}, true);
var job = new cron.CronJob(
'*/1 * * * * *',
function() {
c++;
},
function() {
expect(c).to.eql(5);
done();
},
true
);
for (var i = 0; i < 5; i++)
clock.tick(1000);
for (var i = 0; i < 5; i++) clock.tick(1000);

@@ -192,8 +237,12 @@ clock.restore();

var job = new cron.CronJob('0 */45 * * * *', function() {
c++;
}, null, true);
var job = new cron.CronJob(
'0 */45 * * * *',
function() {
c++;
},
null,
true
);
for (var i = 0; i < 2; i++)
clock.tick(60 * 60 * 1000);
for (var i = 0; i < 2; i++) clock.tick(60 * 60 * 1000);

@@ -209,11 +258,15 @@ clock.restore();

var job = new cron.CronJob('0 */45 * * * *', function() {
c++
}, function() {
expect(c).to.eql(4); // 0 and 45
done();
}, true);
var job = new cron.CronJob(
'0 */45 * * * *',
function() {
c++;
},
function() {
expect(c).to.eql(4); // 0 and 45
done();
},
true
);
for (var i = 0; i < 2; i++)
clock.tick(60 * 60 * 1000);
for (var i = 0; i < 2; i++) clock.tick(60 * 60 * 1000);

@@ -228,8 +281,12 @@ clock.restore();

var job = new cron.CronJob('0 0,45 * * * *', function() {
c++;
}, null, true);
var job = new cron.CronJob(
'0 0,45 * * * *',
function() {
c++;
},
null,
true
);
for (var i = 0; i < 2; i++)
clock.tick(60 * 60 * 1000);
for (var i = 0; i < 2; i++) clock.tick(60 * 60 * 1000);

@@ -245,11 +302,15 @@ clock.restore();

var job = new cron.CronJob('0 0,45 * * * *', function() {
c++
}, function() {
expect(c).to.eql(4); // 0 and 45
done();
}, true);
var job = new cron.CronJob(
'0 0,45 * * * *',
function() {
c++;
},
function() {
expect(c).to.eql(4); // 0 and 45
done();
},
true
);
for (var i = 0; i < 2; i++)
clock.tick(60 * 60 * 1000);
for (var i = 0; i < 2; i++) clock.tick(60 * 60 * 1000);

@@ -264,7 +325,12 @@ clock.restore();

var job = new cron.CronJob('0-8 * * * * *', function() {
c++;
}, null, true);
var job = new cron.CronJob(
'0-8 * * * * *',
function() {
c++;
},
null,
true
);
clock.tick(10000); //run for 10 seconds
clock.tick(10000); // run for 10 seconds

@@ -280,8 +346,13 @@ clock.restore();

var job = new cron.CronJob('0-8 * * * * *', function() {
c++;
}, function() {
expect(c).to.eql(8);
done();
}, true);
var job = new cron.CronJob(
'0-8 * * * * *',
function() {
c++;
},
function() {
expect(c).to.eql(8);
done();
},
true
);

@@ -322,3 +393,3 @@ clock.tick(10000);

},
onComplete: function () {
onComplete: function() {
expect(c).to.eql(1);

@@ -340,11 +411,15 @@ done();

var job = new cron.CronJob('* * * * * *', function() {
c++;
this.stop();
}, function() {
expect(c).to.eql(1);
var job = new cron.CronJob(
'* * * * * *',
function() {
c++;
this.stop();
},
function() {
expect(c).to.eql(1);
clock.restore();
done();
});
clock.restore();
done();
}
);
job.start();

@@ -359,10 +434,15 @@

var clock = sinon.useFakeTimers(d.getTime());
var s = d.getSeconds()+1;
var s = d.getSeconds() + 1;
d.setSeconds(s);
var job = new cron.CronJob(d, function() {
var t = new Date();
expect(t.getSeconds()).to.eql(d.getSeconds());
c++;
}, null, true);
var job = new cron.CronJob(
d,
function() {
var t = new Date();
expect(t.getSeconds()).to.eql(d.getSeconds());
c++;
},
null,
true
);
clock.tick(1000);

@@ -379,13 +459,18 @@

var clock = sinon.useFakeTimers(d.getTime());
var s = d.getSeconds()+1;
var s = d.getSeconds() + 1;
d.setSeconds(s);
var job = new cron.CronJob(d, function() {
var t = new Date();
expect(t.getSeconds()).to.eql(d.getSeconds());
c++;
}, function() {
expect(c).to.eql(1);
done();
}, true);
var job = new cron.CronJob(
d,
function() {
var t = new Date();
expect(t.getSeconds()).to.eql(d.getSeconds());
c++;
},
function() {
expect(c).to.eql(1);
done();
},
true
);
clock.tick(1000);

@@ -398,3 +483,3 @@

describe('with timezone', function() {
it('should run a job using cron syntax', function () {
it('should run a job using cron syntax', function() {
var clock = sinon.useFakeTimers();

@@ -404,4 +489,4 @@

var moment = require("moment-timezone");
var zone = "America/Chicago";
var moment = require('moment-timezone');
var zone = 'America/Chicago';

@@ -413,7 +498,7 @@ // New Orleans time

// Current time
d = moment();
var d = moment();
// If current time is New Orleans time, switch to Los Angeles..
if (t.hours() === d.hours()) {
zone = "America/Los_Angeles";
zone = 'America/Los_Angeles';
t.tz(zone);

@@ -430,5 +515,11 @@ }

// hour than local time.
var job = new cron.CronJob(t.seconds() + ' ' + t.minutes() + ' ' + t.hours() + ' * * *', function(){
c++;
}, null, true, zone);
var job = new cron.CronJob(
t.seconds() + ' ' + t.minutes() + ' ' + t.hours() + ' * * *',
function() {
c++;
},
null,
true,
zone
);

@@ -441,7 +532,7 @@ clock.tick(1000);

it('should run a job using a date', function () {
it('should run a job using a date', function() {
var c = 0;
var moment = require("moment-timezone");
var zone = "America/Chicago";
var moment = require('moment-timezone');
var zone = 'America/Chicago';

@@ -453,7 +544,7 @@ // New Orleans time

// Current time
d = moment();
var d = moment();
// If current time is New Orleans time, switch to Los Angeles..
if (t.hours() === d.hours()) {
zone = "America/Los_Angeles";
zone = 'America/Los_Angeles';
t.tz(zone);

@@ -466,5 +557,11 @@ }

var job = new cron.CronJob(d._d, function() {
c++;
}, null, true, zone);
var job = new cron.CronJob(
d._d,
function() {
c++;
},
null,
true,
zone
);

@@ -477,7 +574,7 @@ clock.tick(1000);

it('should test if timezone is valid.', function () {
expect(function () {
new cron.CronJob({
it('should test if timezone is valid.', function() {
expect(function() {
new cron.CronJob({ // ignore eslint error here
cronTime: '* * * * * *',
onTick: function (){},
onTick: function() {},
timeZone: 'fake/timezone'

@@ -528,3 +625,3 @@ });

expect(c).to.eql(3);
});
});

@@ -557,6 +654,11 @@ it('should start, change time, exception', function() {

var job = new cron.CronJob('* * * * * *', function() {
expect(job).to.be.instanceOf(cron.CronJob);
expect(job).to.eql(this);
}, null, true);
var job = new cron.CronJob(
'* * * * * *',
function() {
expect(job).to.be.instanceOf(cron.CronJob);
expect(job).to.eql(this);
},
null,
true
);

@@ -572,6 +674,13 @@ clock.tick(1000);

var job = new cron.CronJob('* * * * * *', function() {
expect(this.hello).to.eql('world');
expect(job).to.not.eql(this);
}, null, true, null, {'hello':'world'});
var job = new cron.CronJob(
'* * * * * *',
function() {
expect(this.hello).to.eql('world');
expect(job).to.not.eql(this);
},
null,
true,
null,
{ hello: 'world' }
);

@@ -594,3 +703,3 @@ clock.tick(1000);

start: true,
context: {hello: 'world'}
context: { hello: 'world' }
});

@@ -607,8 +716,18 @@

var invalid1 = new cron.CronJob('* 60 * * * *', function() {
assert.ok(true);
}, null, true);
var invalid2 = new cron.CronJob('* * 24 * * *', function() {
assert.ok(true);
}, null, true);
var invalid1 = new cron.CronJob(
'* 60 * * * *',
function() {
expect.ok(true);
},
null,
true
);
var invalid2 = new cron.CronJob(
'* * 24 * * *',
function() {
expect.ok(true);
},
null,
true
);

@@ -632,5 +751,10 @@ clock.tick(1000);

var job = new cron.CronJob('0 0 0 1 * *', function() {
c++;
}, null, true);
var job = new cron.CronJob(
'0 0 0 1 * *',
function() {
c++;
},
null,
true
);

@@ -643,3 +767,3 @@ clock.tick(1001);

clock.tick(2678400001); //jump over 2 firsts
clock.tick(2678400001); // jump over 2 firsts
clock.restore();

@@ -655,5 +779,10 @@ job.stop();

var job = new cron.CronJob('0 * * * * *', function() {
c++;
}, null, true);
var job = new cron.CronJob(
'0 * * * * *',
function() {
c++;
},
null,
true
);

@@ -811,7 +940,7 @@ clock.tick(60000);

describe('with utcOffset', function() {
it('should run a job using cron syntax with number format utcOffset', function () {
it('should run a job using cron syntax with number format utcOffset', function() {
var clock = sinon.useFakeTimers();
var c = 0;
var moment = require("moment-timezone");
var moment = require('moment-timezone');

@@ -824,5 +953,14 @@ // Current time

var job = new cron.CronJob(t.seconds() + ' ' + t.minutes() + ' ' + t.hours() + ' * * *', function(){
c++;
}, null, true, null, null, null, utcOffset);
var job = new cron.CronJob(
t.seconds() + ' ' + t.minutes() + ' ' + t.hours() + ' * * *',
function() {
c++;
},
null,
true,
null,
null,
null,
utcOffset
);

@@ -839,7 +977,7 @@ // tick 1 sec before an hour

it('should run a job using cron syntax with string format utcOffset', function () {
it('should run a job using cron syntax with string format utcOffset', function() {
var clock = sinon.useFakeTimers();
var c = 0;
var moment = require("moment-timezone");
var moment = require('moment-timezone');

@@ -851,3 +989,3 @@ // Current time

var utcOffset = t.utcOffset() - 60;
var utcOffsetString = (0 < utcOffset ? '+' : '-');
var utcOffsetString = utcOffset > 0 ? '+' : '-';
utcOffsetString += ('0' + Math.floor(Math.abs(utcOffset) / 60)).slice(-2);

@@ -857,5 +995,14 @@ utcOffsetString += ':';

var job = new cron.CronJob(t.seconds() + ' ' + t.minutes() + ' ' + t.hours() + ' * * *', function(){
c++;
}, null, true, null, null, null, utcOffsetString);
var job = new cron.CronJob(
t.seconds() + ' ' + t.minutes() + ' ' + t.hours() + ' * * *',
function() {
c++;
},
null,
true,
null,
null,
null,
utcOffsetString
);

@@ -873,15 +1020,19 @@ // tick 1 sec before an hour

it('should run a job using cron syntax with number format utcOffset that is 0', function () {
it('should run a job using cron syntax with number format utcOffset that is 0', function() {
var clock = sinon.useFakeTimers();
var c = 0;
var moment = require("moment-timezone");
var job = new cron.CronJob(
'* * * * * *',
function() {
c++;
},
null,
true,
null,
null,
null,
0
);
// Current time
var t = moment();
var job = new cron.CronJob('* * * * * *', function(){
c++;
}, null, true, null, null, null, 0);
clock.tick(999);

@@ -895,3 +1046,9 @@ expect(c).to.eql(0);

});
it('should be able to detect out of range days of month and fix them', function() {
var ct = new cron.CronTime('* * 32 FEB *');
expect(ct.dayOfMonth['32']).to.eql(undefined);
expect(ct.dayOfMonth['2']).to.eql(true);
});
});
});

@@ -1,8 +0,10 @@

var chai = require('chai'),
expect = chai.expect,
cron = require('../lib/cron');
var chai = require('chai');
var expect = chai.expect;
var cron = require('../lib/cron');
describe('crontime', function () {
it('should test stars (* * * * * *)', function () {
expect(function () {
// most eslint errors here are due to side effects. i don't care much about them right now
describe('crontime', function() {
it('should test stars (* * * * * *)', function() {
expect(function() {
new cron.CronTime('* * * * * *');

@@ -12,4 +14,4 @@ }).to.not.throw(Error);

it('should test digit (0 * * * * *)', function () {
expect(function () {
it('should test digit (0 * * * * *)', function() {
expect(function() {
new cron.CronTime('0 * * * * *');

@@ -19,4 +21,4 @@ }).to.not.throw(Error);

it('should test multi digits (08 * * * * *)', function () {
expect(function () {
it('should test multi digits (08 * * * * *)', function() {
expect(function() {
new cron.CronTime('08 * * * * *');

@@ -26,4 +28,4 @@ }).to.not.throw(Error);

it('should test all digits (08 8 8 8 8 5)', function () {
expect(function () {
it('should test all digits (08 8 8 8 8 5)', function() {
expect(function() {
new cron.CronTime('08 * * * * *');

@@ -33,4 +35,4 @@ }).to.not.throw(Error);

it('should test too many digits (08 8 8 8 8 5)', function () {
expect(function () {
it('should test too many digits (08 8 8 8 8 5)', function() {
expect(function() {
new cron.CronTime('08 * * * * *');

@@ -40,4 +42,4 @@ }).to.not.throw(Error);

it('should test standard cron format (* * * * *)', function () {
expect(function () {
it('should test standard cron format (* * * * *)', function() {
expect(function() {
new cron.CronTime('* * * * *');

@@ -47,3 +49,3 @@ }).to.not.throw(Error);

it('should test standard cron format (8 8 8 8 5)', function () {
it('should test standard cron format (8 8 8 8 5)', function() {
var standard = new cron.CronTime('8 8 8 8 5');

@@ -60,4 +62,4 @@ var extended = new cron.CronTime('0 8 8 8 8 5');

it('should test hyphen (0-10 * * * * *)', function () {
expect(function () {
it('should test hyphen (0-10 * * * * *)', function() {
expect(function() {
new cron.CronTime('0-10 * * * * *');

@@ -67,4 +69,4 @@ }).to.not.throw(Error);

it('should test multi hyphens (0-10 0-10 * * * *)', function () {
expect(function () {
it('should test multi hyphens (0-10 0-10 * * * *)', function() {
expect(function() {
new cron.CronTime('0-10 0-10 * * * *');

@@ -74,4 +76,4 @@ }).to.not.throw(Error);

it('should test all hyphens (0-10 0-10 0-10 0-10 0-10 0-1)', function () {
expect(function () {
it('should test all hyphens (0-10 0-10 0-10 0-10 0-10 0-1)', function() {
expect(function() {
new cron.CronTime('0-10 0-10 0-10 0-10 0-10 0-1');

@@ -81,4 +83,4 @@ }).to.not.throw(Error);

it('should test comma (0,10 * * * * *)', function () {
expect(function () {
it('should test comma (0,10 * * * * *)', function() {
expect(function() {
new cron.CronTime('0,10 * * * * *');

@@ -88,4 +90,4 @@ }).to.not.throw(Error);

it('should test multi commas (0,10 0,10 * * * *)', function () {
expect(function () {
it('should test multi commas (0,10 0,10 * * * *)', function() {
expect(function() {
new cron.CronTime('0,10 0,10 * * * *');

@@ -95,4 +97,4 @@ }).to.not.throw(Error);

it('should test all commas (0,10 0,10 0,10 0,10 0,10 0,1)', function () {
expect(function () {
it('should test all commas (0,10 0,10 0,10 0,10 0,10 0,1)', function() {
expect(function() {
new cron.CronTime('0,10 0,10 0,10 0,10 0,10 0,1');

@@ -102,4 +104,4 @@ }).to.not.throw(Error);

it('should test alias (* * * * jan *)', function () {
expect(function () {
it('should test alias (* * * * jan *)', function() {
expect(function() {
new cron.CronTime('* * * * jan *');

@@ -109,4 +111,4 @@ }).to.not.throw(Error);

it('should test multi aliases (* * * * jan,feb *)', function () {
expect(function () {
it('should test multi aliases (* * * * jan,feb *)', function() {
expect(function() {
new cron.CronTime('* * * * jan,feb *');

@@ -116,4 +118,4 @@ }).to.not.throw(Error);

it('should test all aliases (* * * * jan,feb mon,tue)', function () {
expect(function () {
it('should test all aliases (* * * * jan,feb mon,tue)', function() {
expect(function() {
new cron.CronTime('* * * * jan,feb mon,tue');

@@ -125,4 +127,4 @@ }).to.not.throw(Error);

it('should test unknown alias (* * * * jar *)', function () {
expect(function () {
it('should test unknown alias (* * * * jar *)', function() {
expect(function() {
new cron.CronTime('* * * * jar *');

@@ -132,4 +134,4 @@ }).to.throw(Error);

it('should test unknown alias - short (* * * * j *)', function () {
expect(function () {
it('should test unknown alias - short (* * * * j *)', function() {
expect(function() {
new cron.CronTime('* * * * j *');

@@ -139,9 +141,9 @@ }).to.throw(Error);

it('should test Date', function () {
it('should test Date', function() {
var d = new Date();
var ct = new cron.CronTime(d);
expect(ct.source.isSame(d.getTime())).to.be.true
expect(ct.source.isSame(d.getTime())).to.be.true;
});
it('should test day roll-over', function () {
it('should test day roll-over', function() {
var numHours = 24;

@@ -159,4 +161,4 @@ var ct = new cron.CronTime('0 0 17 * * *');

it('should test illegal repetition syntax', function () {
expect(function () {
it('should test illegal repetition syntax', function() {
expect(function() {
new cron.CronTime('* * /4 * * *');

@@ -166,3 +168,3 @@ }).to.throw(Error);

it('should test next date', function () {
it('should test next date', function() {
var ct = new cron.CronTime('0 0 */4 * * *');

@@ -178,11 +180,13 @@

it('should test next date from invalid date', function () {
it('should throw an exception because next date is invalid', function() {
var ct = new cron.CronTime('0 0 * * * *');
var nextDate = new Date('My invalid date string');
var nextdt = ct._getNextDateFrom(nextDate);
expect(nextdt.toString()).to.eql('Invalid date');
try {
var nextdt = ct._getNextDateFrom(nextDate);
} catch (e) {
expect(e.message).to.eql('ERROR: You specified an invalid date.');
}
});
it('should test next real date', function () {
it('should test next real date', function() {
var ct = new cron.CronTime(new Date());

@@ -199,13 +203,11 @@

describe('should throw an exception because `L` not supported', function () {
it('(* * * L * *)', function () {
expect(function () {
describe('should throw an exception because `L` not supported', function() {
it('(* * * L * *)', function() {
expect(function() {
new cron.CronTime('* * * L * *');
}).to.throw(Error);
});
it('(* * * * * L)', function () {
expect(function () {
it('(* * * * * L)', function() {
expect(function() {
new cron.CronTime('* * * * * L');

@@ -216,43 +218,44 @@ }).to.throw(Error);

it('should strip off millisecond', function () {
it('should strip off millisecond', function() {
var cronTime = new cron.CronTime('0 */10 * * * *');
var x = cronTime._getNextDateFrom(new Date("2018-08-10T02:20:00.999Z"));
var x = cronTime._getNextDateFrom(new Date('2018-08-10T02:20:00.999Z'));
expect(x.toISOString()).to.equal('2018-08-10T02:30:00.000Z');
});
it('should strip off millisecond (2)', function () {
it('should strip off millisecond (2)', function() {
var cronTime = new cron.CronTime('0 */10 * * * *');
var x = cronTime._getNextDateFrom(new Date("2018-08-10T02:19:59.999Z"));
var x = cronTime._getNextDateFrom(new Date('2018-08-10T02:19:59.999Z'));
expect(x.toISOString()).to.equal('2018-08-10T02:20:00.000Z');
});
it('should generete the right next days when cron is set to every minute', function () {
it('should generete the right next days when cron is set to every minute', function() {
var cronTime = new cron.CronTime('* * * * *');
var min=60000;
var previousDate=new Date(Date.UTC(2018,5,3,0,0));
for(var i=0;i<25;i++){
var min = 60000;
var previousDate = new Date(Date.UTC(2018, 5, 3, 0, 0));
for (var i = 0; i < 25; i++) {
var nextDate = cronTime._getNextDateFrom(previousDate);
expect(nextDate.valueOf()).to.equal(previousDate.valueOf()+min)
previousDate=nextDate;
expect(nextDate.valueOf()).to.equal(previousDate.valueOf() + min);
previousDate = nextDate;
}
});
it('should generete the right next days when cron is set to every 15 min', function () {
it('should generete the right next days when cron is set to every 15 min', function() {
var cronTime = new cron.CronTime('*/15 * * * *');
var min=60000*15;
var previousDate=new Date(Date.UTC(2016,6,3,0,0));
for(var i=0;i<25;i++){
var min = 60000 * 15;
var previousDate = new Date(Date.UTC(2016, 6, 3, 0, 0));
for (var i = 0; i < 25; i++) {
var nextDate = cronTime._getNextDateFrom(previousDate);
expect(nextDate.valueOf()).to.equal(previousDate.valueOf()+min)
previousDate=nextDate;
expect(nextDate.valueOf()).to.equal(previousDate.valueOf() + min);
previousDate = nextDate;
}
});
it('should generete the right next day when cron is set to every 15 min in Feb', function () {
it('should generete the right next day when cron is set to every 15 min in Feb', function() {
var cronTime = new cron.CronTime('*/15 * * FEB *');
var min=60000*15;
var previousDate=new Date(Date.UTC(2018,3,0,0,0));
var nextDate = cronTime._getNextDateFrom(previousDate,"UTC");
expect(nextDate.valueOf()).to.equal(new Date(Date.UTC(2019,1,1,0,0)).valueOf());
var previousDate = new Date(Date.UTC(2018, 3, 0, 0, 0));
var nextDate = cronTime._getNextDateFrom(previousDate, 'UTC');
expect(nextDate.valueOf()).to.equal(
new Date(Date.UTC(2019, 1, 1, 0, 0)).valueOf()
);
});
});

Sorry, the diff of this file is not supported yet

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