cron-converter
Cron string parser for node and the browser
Install
Npm
yarn add cron-converter
or
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]);
schedule = cronInstance.schedule(reference);
console.log(schedule.next().format());
console.log(schedule.next().format());
schedule.reset();
console.log(schedule.prev().format());
console.log(schedule.prev().format());
Constructor options
outputWeekdayNames and outputMonthNames
Default: false
var cronInstance = new Cron({
outputWeekdayNames: true,
outputMonthNames: true
});
cronInstance.fromString('*/5 9-17/2 * 1-3 1-5');
console.log(cronInstance.toString());
outputHashes
Default: false
var cronInstance = new Cron({
outputHashes: true
});
cronInstance.fromString('*/5 9-17/2 * 1-3 1-5');
console.log(cronInstance.toString());
timezone
Default: Local timezone
var cronInstance = new Cron({
timezone: "Europe/London"
});
cronInstance.fromString('*/5 9-17/2 * 1-3 1-5');
console.log(cronInstance.schedule().next());
Test and build
git clone https://github.com/roccivic/cron-converter
cd cron-converter
yarn install
yarn build
Run yarn watch
to continuously run unit tests as you edit the code