Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 way

fmt.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
*/
```