Skip to content

Commit

Permalink
feat: added timezones support and migrated from date-fns to moment.js…
Browse files Browse the repository at this point in the history
…, hours configuration is now in

BREAKING CHANGE: hours configuration must be updated to new format
  • Loading branch information
stefanoTron committed Nov 18, 2017
1 parent 9c7c4d0 commit f5b40d2
Show file tree
Hide file tree
Showing 14 changed files with 666 additions and 274 deletions.
175 changes: 101 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# business-hours.js
Handle business hours of a restaurant, office or any other business. Highly customizable with lots of features.
Handle business hours of a restaurant, office or any other business. Highly customizable with lots of features, based on moment.js.

[Demo](https://codesandbox.io/s/github/littletower/business-hours.js/tree/master/example)

[Demo](https://business-hours-example.herokuapp.com/)

[![Travis](https://img.shields.io/travis/littletower/business-hours.js.svg?style=flat-square)]()
[![Codecov](https://img.shields.io/codecov/c/github/littletower/business-hours.js.svg?style=flat-square)]()
Expand All @@ -20,80 +21,82 @@ yarn add business-hours.js

# Configuration

To get started, setup a JSON file where you define the business hours.

`0` stands for `Sunday`<br>
`1` stands for `Monday` and so on.
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.

```json
{
"0": [
{
"from": "10:00",
"to": "13:30"
},
{
"from": "17:00",
"to": "20:00"
},
{
"from": "21:00",
"to": "24:00"
}
],
"1": [
{
"from": "10:00",
"to": "13:30"
},
{
"from": "18:00",
"to": "22:00"
}
],
"2": "closed",
"3": [
{
"from": "10:00",
"to": "13:30"
},
{
"from": "18:00",
"to": "22:00"
}
],
"4": [
{
"from": "10:00",
"to": "13:30"
},
{
"from": "18:00",
"to": "22:00"
}
],
"5": [
{
"from": "10:00",
"to": "13:30"
},
{
"from": "18:00",
"to": "22:00"
}
],
"6": [
{
"from": "10:00",
"to": "13:30"
},
{
"from": "18:00",
"to": "22:00"
}
]
"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"
}
```

Expand All @@ -114,9 +117,33 @@ 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](example/)

# 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
- [ ] use ISO formate for weekday, meaning, starting the week on Monday instead of Sunday
- [ ] add holidays (single day or range) in ISO (ISO 8601) format YYYY-MM-DD
- [ ] 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
Loading

0 comments on commit f5b40d2

Please sign in to comment.