cron-test

1.0.2 • Public • Published

cron-test

Simple utility to check whether a date matches a cron expression.

Butchered from cron-parser.

Setup

npm install cron-test

Supported format

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    |
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, optional)

Supports mixed use of ranges and range increments (L, W and # characters are not supported currently). See below for example

Usage

Simple expression.

const test = require('cron-test');
 
// Every hour from 0 through 9 and 23 on every day-of-week from Monday through Friday
const interval = test.parseExpression('* 0-9,23 * * 1-5');
const date1 = new Date('2017-12-06T08:13:42.770Z');
const date2 = new Date('2017-12-06T12:13:42.770Z');
 
interval.test(date1) // true
interval.test(date2) // false
 

Dependents (1)

Package Sidebar

Install

npm i cron-test

Weekly Downloads

5

Version

1.0.2

License

MIT

Unpacked Size

20.3 kB

Total Files

8

Last publish

Collaborators

  • benlewis