0.0.43 • Published 3 years ago

cron-allowed-range v0.0.43

Weekly downloads
132
License
Apache-2.0
Repository
github
Last release
3 years ago

CircleCI Coverage
Status npm
version

cron-allowed-range

Use cron-like expressions to test if a datetime is in an allowed range.

Usage

API

npm install cron-allowed-range
const CronAllowedRange = require('cron-allowed-range');

/* Allowed if it is:
 * - At any minute
 * - Between 9 AM - 6 PM
 * - On any day of the month
 * - Between September to June, or on August
 * - Between Monday to Friday
 */
const cr = new CronAllowedRange('* 9-17 * 9-6,8 1-5', 'America/Toronto');

cr.isDateAllowed(new Date('December 18, 1995 08:59:59 GMT-0500'));
// false

cr.isDateAllowed(new Date('August 18, 1995 17:00:00 GMT-0400'));
// true

CLI

npm install -g cron-allowed-range

cr -e '* 9-17 * * *' -t 'America/Toronto'

echo $?
# exit code is 0 if current time is within range, otherwise 1

Formatting the Cron-Like Expression

* represents any value
, separator (e.g. 5,6)
- used to define (inclusive) ranges (e.g. 5-9)
/ not supported
┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of the month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)
│ │ │ │ │
│ │ │ │ │
│ │ │ │ │
* * * * *

Diagram from Wikipedia

0.0.43

3 years ago

0.0.42

3 years ago

0.0.41

3 years ago

0.0.40

3 years ago

0.0.38

4 years ago

0.0.39

3 years ago

0.0.37

4 years ago

0.0.36

4 years ago

0.0.35

4 years ago

0.0.34

4 years ago

0.0.33

4 years ago

0.0.32

4 years ago

0.0.31

4 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.28

5 years ago

0.0.27

5 years ago

0.0.26

5 years ago

0.0.25

5 years ago

0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago