Git Product home page Git Product logo

gssrinivas59 / business-hours.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stefanotron/business-hours.js

0.0 0.0 0.0 1.35 MB

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

Home Page: https://codesandbox.io/s/github/littletower/business-hours.js/tree/master/example

License: MIT License

JavaScript 91.81% CSS 1.97% HTML 6.21%

business-hours.js's Introduction

business-hours.js ๐Ÿ•’

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

โ€ผ๏ธ Demo โ€ผ๏ธ

Travis Codecov npm

Features ๐Ÿ’ฅ

  • 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)
  • Time zones support
  • use ISO format for weekdays, meaning, starting the week on Monday instead of Sunday
  • 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

business-hours.js's People

Contributors

stefanotron avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.