cron
Advanced tools
Comparing version 0.3.4 to 1.0.0
@@ -29,6 +29,7 @@ var CronDate = Date; | ||
CronTime.map = ['second', 'minute', 'hour', 'dayOfMonth', 'month', 'dayOfWeek']; | ||
CronTime.constraints = [ [0, 59], [0, 59], [0, 23], [1, 31], [0, 11], [1, 7] ]; | ||
CronTime.constraints = [ [0, 59], [0, 59], [0, 23], [1, 31], [0, 11], [0, 6] ]; | ||
CronTime.parseDefaults = [ '0', '*', '*', '*', '*', '*' ]; | ||
CronTime.aliases = { | ||
jan:0, feb:1, mar:2, apr:3, may:4, jun:5, jul:6, aug:7, sep:8, oct:9, nov:10, dec:11, | ||
sun:1, mon:2, tue:3, wed:4, thu:5, fri:6, sat:7 | ||
sun:0, mon:1, tue:2, wed:3, thu:4, fri:5, sat:6 | ||
}; | ||
@@ -111,3 +112,3 @@ | ||
if (!(date.getDay()+1 in this.dayOfWeek)) { | ||
if (!(date.getDay() in this.dayOfWeek)) { | ||
date.setDate(date.getDate()+1); | ||
@@ -184,7 +185,10 @@ date.setHours(0); | ||
split = source.replace(/^\s\s*|\s\s*$/g, '').split(/\s+/), | ||
cur, len = 6; | ||
while (len--) { | ||
cur = split[len] || '*'; | ||
this._parseField(cur, CronTime.map[len], CronTime.constraints[len]); | ||
cur, i = 0, len = CronTime.map.length; | ||
for (; i < CronTime.map.length; i++) { | ||
// If the split source string doesn't contain all digits, | ||
// assume defaults for first n missing digits. | ||
// This adds support for 5-digit standard cron syntax | ||
cur = split[i - (len - split.length)] || CronTime.parseDefaults[i]; | ||
this._parseField(cur, CronTime.map[i], CronTime.constraints[i]); | ||
} | ||
@@ -191,0 +195,0 @@ }, |
{ | ||
"name": "cron", | ||
"description": "CronJob's for your node", | ||
"version": "0.3.4", | ||
"version": "1.0.0", | ||
"author": "Nick Campbell <nicholas.j.campbell@gmail.com> (http://github.com/ncb000gt)", | ||
@@ -6,0 +6,0 @@ "bugs" : { |
@@ -10,4 +10,19 @@ node-cron | ||
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. | ||
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 suported here extend on the standard Unix format to support seconds digits, leaving it off will default to 0 and match the Unix behavior. | ||
Versions and Backwards compatability 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. | ||
<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): | ||
@@ -29,3 +44,3 @@ ========== | ||
[Read up on cron patterns here](http://help.sap.com/saphelp_xmii120/helpdata/en/44/89a17188cc6fb5e10000000a155369/content.htm). | ||
[Read up on cron patterns here](http://crontab.org). | ||
@@ -36,3 +51,3 @@ Another cron example | ||
var cronJob = require('cron').CronJob; | ||
var job = new cronJob('00 30 11 * * 2-6', function(){ | ||
var job = new cronJob('00 30 11 * * 1-5', function(){ | ||
// Runs every weekday (Monday through Friday) | ||
@@ -66,3 +81,3 @@ // at 11:30:00 AM. It does not run on Saturday | ||
var job = new cronJob({ | ||
cronTime: '00 30 11 * * 2-6', | ||
cronTime: '00 30 11 * * 1-5', | ||
onTick: function() { | ||
@@ -69,0 +84,0 @@ // Runs every weekday (Monday through Friday) |
@@ -37,2 +37,22 @@ var testCase = require('nodeunit').testCase, | ||
}, | ||
'test standard cron no-seconds syntax doesnt send on seconds (* * * * *)': function(assert) { | ||
assert.expect(0); | ||
// Delay test from running at minute boundary | ||
var prepDate = new Date(); | ||
if (prepDate.getSeconds() >= 55) { | ||
setTimeout(testRun, 5000); | ||
} else { | ||
testRun(); | ||
} | ||
function testRun() { | ||
var c = new cron.CronJob('* * * * *', function() { | ||
assert.ok(true); | ||
}, null, true); | ||
setTimeout(function() { | ||
c.stop(); | ||
assert.done(); | ||
}, 5250); | ||
} | ||
}, | ||
'test every second for 5 seconds with oncomplete (* * * * * *)': function(assert) { | ||
@@ -39,0 +59,0 @@ assert.expect(6); |
@@ -40,2 +40,17 @@ var testCase = require('nodeunit').testCase, | ||
}, | ||
'test no second digit doesnt throw, i.e. standard cron format (8 8 8 8 5)': function(assert) { | ||
assert.expect(1); | ||
assert.doesNotThrow(function() { | ||
new cron.CronTime('* * * * *'); | ||
}); | ||
assert.done(); | ||
}, | ||
'test no second digit defaults to 0, i.e. standard cron format (8 8 8 8 5)': function(assert) { | ||
assert.expect(1); | ||
var now = new Date(); | ||
var standard = new cron.CronTime('8 8 8 8 5'); | ||
var extended = new cron.CronTime('0 8 8 8 8 5'); | ||
assert.ok(standard._getNextDateFrom(now).getTime() === extended._getNextDateFrom(now).getTime()); | ||
assert.done(); | ||
}, | ||
'test hyphen (0-10 * * * * *)': function(assert) { | ||
@@ -42,0 +57,0 @@ assert.expect(1); |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
30674
757
1
159