Git Product home page Git Product logo

cron-converter's Introduction

cron-converter

Cron string parser for node and the browser

MIT License Badge npm Bower Build Status Coverage Status

Dependency Status devDependency Status Code Climate Inline docs todofy badge

Saucelabs Test Status

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

// Every 10 mins between 9am and 5pm on the 1st of every month
cronInstance.fromString('*/10 9-17 1 * *');

// Prints: '*/10 9-17 1 * *'
console.log(cronInstance.toString());

// Prints:
// [
//   [ 0, 10, 20, 30, 40, 50 ],
//   [ 9, 10, 11, 12, 13, 14, 15, 16, 17 ],
//   [ 1 ],
//   [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ],
//   [ 0, 1, 2, 3, 4, 5, 6 ]
// ]
console.log(cronInstance.toArray());

Parse an Array

cronInstance.fromArray([[0], [1], [1], [5], [0,2,4,6]]);

// Prints: '0 1 1 5 */2'
console.log(cronInstance.toString());

Get the schedule execution times

// Parse a string to init a schedule
cronInstance.fromString('*/5 * * * *');

// Get the iterator, initialised to now
var schedule = cronInstance.schedule();

// Optionally, use a reference Date or moment object
var reference = new Date(2013, 2, 8, 9, 32);
reference = moment([2013, 2, 8, 9, 32]);
// And pass the reference to .schedule()
schedule = cronInstance.schedule(reference);

// Calls to ```.next()``` and ```.prev()```
// return a Moment.js object

// Prints: '2013-03-08T09:35:00+00:00''
console.log(schedule.next().format());
// Prints: '2013-03-08T09:40:00+00:00''
console.log(schedule.next().format());

// Reset
schedule.reset();

// Prints: '2013-03-08T09:30:00+00:00''
console.log(schedule.prev().format());
// Prints: '2013-03-08T09:25:00+00:00''
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');
// Prints: '*/5 *(10-16)/2 * JAN-MAR MON-FRI'
console.log(cronInstance.toString());

outputHashes

Default: false

var cronInstance = new Cron({
  outputHashes: true
});
cronInstance.fromString('*/5 9-17/2 * 1-3 1-5');
// Prints: 'H/5 H(10-16)/2 H 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');
// Finds the next execution time in the London timezone
console.log(cronInstance.schedule().next());

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

cron-converter's People

Contributors

roccivic avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.