Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neverendingqs/cron-allowed-range
Use cron-like expressions to test if a datetime is in an allowed range.
https://github.com/neverendingqs/cron-allowed-range
Last synced: 6 days ago
JSON representation
Use cron-like expressions to test if a datetime is in an allowed range.
- Host: GitHub
- URL: https://github.com/neverendingqs/cron-allowed-range
- Owner: neverendingqs
- License: apache-2.0
- Created: 2019-10-18T19:15:36.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T04:58:22.000Z (over 1 year ago)
- Last Synced: 2024-10-05T06:50:18.599Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 584 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![CircleCI](https://circleci.com/gh/neverendingqs/cron-allowed-range.svg?style=svg)](https://circleci.com/gh/neverendingqs/cron-allowed-range)
[![Coverage
Status](https://coveralls.io/repos/github/neverendingqs/cron-allowed-range/badge.svg?branch=master)](https://coveralls.io/github/neverendingqs/cron-allowed-range?branch=master)
[![npm
version](https://badge.fury.io/js/cron-allowed-range.svg)](https://badge.fury.io/js/cron-allowed-range)# cron-allowed-range
Use cron-like expressions to test if a datetime is in an allowed range.## Usage
### API
```sh
npm install cron-allowed-range
``````js
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'));
// falsecr.isDateAllowed(new Date('August 18, 1995 17:00:00 GMT-0400'));
// true
```### CLI
```sh
npm install -g cron-allowed-rangecr -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](https://en.wikipedia.org/wiki/Cron#Overview)_