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('*/10 9-17 1 * *');
console.log(cronInstance.toString());
console.log(cronInstance.toArray());
Parse an Array
cronInstance.fromArray([[0], [1], [1], [5], [0,2,4,6]]);
console.log(cronInstance.toString());
Get the schedule execution times
cronInstance.fromString('*/5 * * * *');
var schedule = cronInstance.schedule();
var reference = new Date(2013, 2, 8, 9, 32);
reference = moment([2013, 2, 8, 9, 32]);
reference = moment([2013, 2, 8, 9, 32]).tz("Europe/London");
schedule = cronInstance.schedule(reference);
console.log(schedule.next());
console.log(schedule.next());
schedule.reset();
console.log(schedule.prev());
console.log(schedule.prev());
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