Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cron-converter

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cron-converter

Cron string converter

  • 0.0.9
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

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);
// or
reference = moment([2013, 2, 8, 9, 32]);
// or, if you need to support timezones (requires moment-timezone)
reference = moment([2013, 2, 8, 9, 32]).tz("Europe/London");
// And pass the reference to .schedule()
schedule = cronInstance.schedule(reference);

// Prints: 'Fri Feb 08 2013 09:35:00 GMT+0000 (GMT Standard Time)'
console.log(schedule.next());
// Prints: 'Fri Feb 08 2013 09:40:00 GMT+0000 (GMT Standard Time)'
console.log(schedule.next());

// Reset
schedule.reset();

// Prints: 'Fri Feb 08 2013 09:30:00 GMT+0000 (GMT Standard Time)'
console.log(schedule.prev());
// Prints: 'Fri Feb 08 2013 09:25:00 GMT+0000 (GMT Standard Time)'
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');

// Prints: 'H/5 H(10-16)/2 H JAN-MAR MON-FRI'
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

Keywords

FAQs

Package last updated on 11 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc