Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chneau/openhours
A "opening_hours" from openstreetmap like
https://github.com/chneau/openhours
golang opening-hours schedule
Last synced: about 6 hours ago
JSON representation
A "opening_hours" from openstreetmap like
- Host: GitHub
- URL: https://github.com/chneau/openhours
- Owner: chneau
- License: mit
- Created: 2019-03-04T12:10:41.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-20T11:59:19.000Z (3 months ago)
- Last Synced: 2024-08-20T14:00:19.965Z (3 months ago)
- Topics: golang, opening-hours, schedule
- Language: Go
- Homepage:
- Size: 53.7 KB
- Stars: 3
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# openhours
A compromise of complexity of the ["opening_hours"](https://wiki.openstreetmap.org/wiki/Key:opening_hours).
Only the `day-day time-time" will work for now.## Online tools
## Example
```go
oh := openhours.New("Mo-Fr 09:00-17:00")
t := time.Date(2019, 3, 6, 10, 0, 0, 0, time.Now().Location())
// oh.Location = t.Location() //default to system but can be changed this wayfmt.Println("t =", t)
isOpen := oh.Match(t)
fmt.Println("Is it open at this date?", isOpen)_, duration := oh.NextDur(t)
fmt.Println("For how long?", duration)_, date := oh.NextDate(t)
fmt.Println("When will it close?", date)fmt.Println(" +++++++++++++++++++++ ")
t = time.Date(2019, 3, 6, 18, 0, 0, 0, time.Now().Location())
fmt.Println("t =", t)
isOpen, date = oh.NextDate(t)
fmt.Println("Is it open?", isOpen, "Ok, when will it open then ?", date)/* output
t = 2019-03-06 10:00:00 +0000 GMT
Is it open at this date? true
For how long? 7h0m0s
When will it close? 2019-03-06 17:00:00 +0000 GMT
+++++++++++++++++++++
t = 2019-03-06 18:00:00 +0000 GMT
Is it open? false Ok, when will it open then ? 2019-03-07 09:00:00 +0000 GMT
*/
```