cron-converter
Cron string parser for node and the browser
Install
Npm
npm install cron-converter --save
Bower
bower install cron-converter --save
Use
This step is for usage from node,
the bower build exposes a global
var Cron = require('cron-converter');
Create a new instance
var cronInstance = new Cron();
Parse a cron string
cronInstance.fromString('1 1 1 1 1');
console.log(cronInstance.toArray());
console.log(cronInstance.toString());
Validate an Array
cronInstance.fromArray([[0], [1], [1], [5], [0,2,4,6]]);
console.log(cronInstance.toString());
Get next and last execution times
Assuming now it is 09:32:00 on 08 Feb 2013
cronInstance.fromString('*/5 * * * *');
console.log(cronInstance.next());
console.log(cronInstance.prev());
Pass a reference Date
cronInstance.fromString('*/5 * * * *');
var now = new Date(2015, 6, 7, 15, 23);
console.log(cronInstance.next(now));
console.log(cronInstance.prev(now));
Constructor options
All default to false
var cronInstance = new Cron({
outputWeekdayNames: true,
outputMonthNames: true,
outputHashes: true
});
cronInstance.fromString('*/5 9-17/2 * 1-3 1-5');
console.log(cronInstance.toString());
Test and build
git clone https://github.com/roccivic/cron-converter
cd cron-converter
npm install -g gulp
npm install
gulp
Run gulp watch
to continuously run unit tests as you edit the code