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

cron-allowed-range

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cron-allowed-range

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

  • 0.0.43
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 01 Aug 2022

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