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

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

cron-converter

Cron string parser for node and the browser

npm version Bower version

Build status Coverage Status dependencies Status

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

// 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
yarn install
yarn build

Run yarn watch to continuously run unit tests as you edit the code

Keywords

FAQs

Package last updated on 02 May 2021

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