Comparing version 1.6.0 to 1.7.0
@@ -146,3 +146,3 @@ (function(root, factory) { | ||
if (this.realDate) { | ||
const diff = moment().diff(date); | ||
const diff = moment().diff(date, 's'); | ||
if (diff > 0) { | ||
@@ -298,5 +298,13 @@ throw new Error('WARNING: Date in past. Will never be fired.'); | ||
origDate = moment(date); | ||
var curHour = date.hours(); | ||
date.hours( | ||
date.hours() === 23 && diff > 86400000 ? 0 : date.hours() + 1 | ||
date.hours() === 23 && diff > 86400000 ? 0 : date.hours() + 1 | ||
); | ||
/* | ||
* Moment Date will not allow you to set the time to 2 AM if there is no 2 AM (on the day we change the clock) | ||
* We will therefore jump to 3AM if time stayed at 1AM | ||
*/ | ||
if(curHour === date.hours()){ | ||
date.hours(date.hours() + 2); | ||
} | ||
date.minutes(0); | ||
@@ -303,0 +311,0 @@ date.seconds(0); |
{ | ||
"name": "cron", | ||
"description": "Cron jobs for your node", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"author": "Nick Campbell <nicholas.j.campbell@gmail.com> (http://github.com/ncb000gt)", | ||
@@ -21,14 +21,14 @@ "bugs": { | ||
"devDependencies": { | ||
"mocha": "~5.1.x", | ||
"chai": "~4.1.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" | ||
"mocha": "~5.2.x", | ||
"chai": "~4.2.x", | ||
"sinon": "~7.2.x", | ||
"eslint": "~5.13.x", | ||
"eslint-config-prettier": "~4.0.x", | ||
"eslint-config-standard": "~12.0.x", | ||
"eslint-plugin-import": "~2.16.x", | ||
"eslint-plugin-node": "~8.0.x", | ||
"eslint-plugin-prettier": "~3.0.x", | ||
"eslint-plugin-promise": "~4.0.x", | ||
"eslint-plugin-standard": "~4.0.x", | ||
"prettier": "~1.16.x" | ||
}, | ||
@@ -35,0 +35,0 @@ "keywords": [ |
@@ -111,2 +111,5 @@ node-cron | ||
revisit it. | ||
* Arrow Functions for `onTick` | ||
Arrow functions get their `this` context from their parent scope. Thus, if you use them, you will not get | ||
the `this` context of the cronjob. You can read a little more in this ticket [GH-40](https://github.com/kelektiv/node-cron/issues/47#issuecomment-459762775) | ||
@@ -113,0 +116,0 @@ |
@@ -742,3 +742,5 @@ var chai = require('chai'); | ||
var c = 0; | ||
var clock = sinon.useFakeTimers('setTimeout'); | ||
var clock = sinon.useFakeTimers({ | ||
toFake: ['setTimeout'] | ||
}); | ||
@@ -871,2 +873,27 @@ var job = new cron.CronJob( | ||
it('should trigger onTick at midnight', function() { | ||
var c = 0; | ||
var d = new Date('12/31/2014'); | ||
d.setSeconds(59); | ||
d.setMinutes(59); | ||
d.setHours(23); | ||
var clock = sinon.useFakeTimers(d.getTime()); | ||
var job = new cron.CronJob({ | ||
cronTime: '00 * * * * *', | ||
onTick: function() { | ||
c++; | ||
}, | ||
start: true, | ||
timeZone: 'UTC' | ||
}); | ||
clock.tick(1000); // move clock 1 second | ||
expect(c).to.eql(1); | ||
clock.restore(); | ||
job.stop(); | ||
expect(c).to.eql(1); | ||
}); | ||
it('should run every day UTC', function() { | ||
@@ -873,0 +900,0 @@ var c = 0; |
@@ -173,3 +173,3 @@ var chai = require('chai'); | ||
it('should test next real date', function() { | ||
var initialDate = new Date() | ||
var initialDate = new Date(); | ||
var ct = new cron.CronTime(initialDate); | ||
@@ -176,0 +176,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
65267
28
1957
196