npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

business-hours.js

v2.0.2

Published

Business hours javascript lib

Downloads

25

Readme

business-hours.js :clock3:

Handle business hours of a restaurant, office or any other business. Highly customizable with lots of features, based on moment.js.

:bangbang: Demo :bangbang:

Travis Codecov npm

Features :boom:

  • all your business hours in JSON format

  • split hours (eg. restaurants, from 10:00 to 14:00 and from 18:00 to 22:00)

  • timezone support

  • add holidays (single day or ranges)

  • based on moment.js

  • lightweight less than 115kB (minified + gzipped)

Installation

Add the latest version of business-hours.js to your package.json:

npm install business-hours.js --save

or

yarn add business-hours.js

Configuration

To get started, you'll need to define your business hours in JSON format for every weekday.

You can have 1 to N from/to pairs per weekday. If on a given day you are closed, instead of a from/to pair, just put closed.

In holidays you can define on which day the business is closed for holidays. It can be one day (YYYY/MM/DD) or a range (YYYY/MM/DD-YYYY/MM/DD).

Set the desired timezone in timeZone, use any tz timezone.

"Monday": [
  {
    "from": "10:00",
    "to": "13:30"
  },
  {
    "from": "18:00",
    "to": "22:00"
  }
],
"Tuesday": "closed",
"Wednesday": [
  {
    "from": "10:00",
    "to": "13:30"
  },
  {
    "from": "18:00",
    "to": "22:00"
  }
],
"Thursday": [
  {
    "from": "10:00",
    "to": "13:30"
  },
  {
    "from": "18:00",
    "to": "22:00"
  }
],
"Friday": [
  {
    "from": "10:00",
    "to": "13:30"
  },
  {
    "from": "18:00",
    "to": "22:00"
  }
],
"Saturday": [
  {
    "from": "10:00",
    "to": "13:30"
  },
  {
    "from": "18:00",
    "to": "22:00"
  }
],
"Sunday": [
  {
    "from": "10:00",
    "to": "13:30"
  },
  {
    "from": "17:00",
    "to": "20:00"
  },
  {
    "from": "21:00",
    "to": "24:00"
  }
],
"holidays": ["2017/12/11", "2017/12/23-2018/01/02"],
"timeZone":"Europe/Amsterdam"
}

Usage

First import the lib

import businessHours from "business-hours.js";

Then you have to initalize the lib with your business hours

businessHours.init(hoursJson);

hoursJson must be in JSON format. It could come from an external file

import hoursJson from "./hours.json";

or it could come from any other endpoint (DB, GraphQL, Firebase...), as long as it's in JSON.

Example

To check if your business is currently open:

let isBusinessOpenNow = businessHours.isOpenNow(); //returns boolean value

Find a whole example in React here here

Doc

Method | Argument | Description ------ | -------- | ----------- isOpenNow | optional : date | Returns if your business is open or not. If an argument is provided, the method will be executed for the given date. isClosedNow | optional : date | Returns if your business is closed or not. If an argument is provided, the method will be executed for the given date. willBeOpenOn | date | Returns if your business will be open on given date. isOpenTomorrow | | Returns if your business is open tomorrow. isOpenAfterTomorrow | | Returns if your business is open after tomorrow. nextOpeningDate | optional : boolean | Returns the next opening date. If argument is set to true, the next opening date could be today. nextOpeningHour | | Returns the next opening hour. isOnHoliday | optional : date | Returns if your business is closed for holidays. isOnHolidayInDays | integer | Returns if your business will be closed for holidays in x days.

TODOs

  • [ ] support after midnight hours, (eg. open from 18:00 to 03:00)
  • [x] Time zones support
  • [x] use ISO format for weekdays, meaning, starting the week on Monday instead of Sunday
  • [x] add holidays (single day or range) in ISO (ISO 8601) format YYYY-MM-DD
  • [ ] support hourly holidays, like business opens from 20:00 instead of 18:00 on a given date.
  • [ ] add always closed on public holidays (country specific)
  • [ ] add localized formatter to display all the business hours
  • [ ] show holiday formatted range starting from a given date