1.1.5 • Published 3 years ago

check-if-is-open-cron v1.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

npm.io npm.io install size npm.io npm.io tested with jest npm.io

Check If Is Open Cron

General information

Small script to know if a business/service is open or closed from a date.

Get started

npm i check-if-is-open-cron

Define an object with opening hours like this:

const opening = {
  timeZone: "Europe/Paris",
  weekDay: {
    default: "* 10-12,14-18 * * 1-5"
  },
  holidays: {
    isOpen: false,
    country: "FR",
    region: null,
    state: null,
    checkHolidaysTypes: ['public']
  }
};

Here is open from Monday to Friday from 1O to 11:59 & 14 to 17:59

To override Monday open hours to 16:00 to 17:59 add this 1: "* 16-18 * * *"

const checkIsOpenCron = require("check-if-is-open-cron");

const opening = {
  timeZone: "Europe/Paris",
  weekDay: {
    default: "* 10-12,14-18 * * 1-5",
    3: "* 16-18 * * *"
  },
  holidays: {
    isOpen: false,
    country: "FR",
    region: null,
    state: null,
    checkHolidaysTypes: ["public"]
  }
};

if (!checkIsOpenCron(opening)) {
  console.log("🛑 Closed 🛑");
} else {
  console.log("🟢 Open 🟢");
}
ParameterSub-ParameterTypeDescriptionSample
timeZonestringTimeZone definitionEurope/Paris
weekDayobjectCron open/close definition
defaultstringCron to apply by default* 10-12,14-18 * * 1-5
0 - 6stringSpecific Cron for Sunday to Saturday* 16-18 * * *
holidaysobjetBased on date-holidays plugin
isOpenbooleantrue if holidays does not influence open / close
countrystringSupported Countries list are on date-holidays plugin
regionstringSupported Regions list are on date-holidays plugin
statestringSupported State list are on date-holidays plugin
checkHolidaysTypesstringSupported Types list are on date-holidays plugin

Types of checkHolidaysTypes

Currently the following type with their meaning are supported. Based on date-holidays plugin

TypeMeaning
publicpublic holiday
bankbank holiday, banks and offices are closed
schoolschool holiday, schools are closed
optionalmajority of people take a day off
observanceoptional festivity, no paid day off

Cron notation

Crontab

Dependencies:

dayjs / lodash / cron-parser / date-holidays

Run test

npm run test

License

MIT