Introduction | opening-hours-go | Spatie       

 SPATIE  

opening-hours-go
================

spatie.be/open-source

  [Docs](https://spatie.be/index.php/docs)  [Opening-hours-go](https://spatie.be/index.php/docs/opening-hours-go/v1)  Introduction

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/opening-hours-go/v1) 

  Introduction    
- [ Introduction ](https://spatie.be/index.php/docs/opening-hours-go/v1/introduction)
- [ Installation and setup ](https://spatie.be/index.php/docs/opening-hours-go/v1/installation-and-setup)
- [ Usage ](https://spatie.be/index.php/docs/opening-hours-go/v1/usage)
- [ Testing ](https://spatie.be/index.php/docs/opening-hours-go/v1/testing)
- [ Releasing ](https://spatie.be/index.php/docs/opening-hours-go/v1/releasing)
- [ Changelog ](https://spatie.be/index.php/docs/opening-hours-go/v1/changelog)
- [ Support us ](https://spatie.be/index.php/docs/opening-hours-go/v1/support-us)

  Opening-hours-go 
==================

 A helper to query and format a set of opening hours 

### Useful links

- [Repository](https://github.com/spatie/opening-hours-go)
- [Discussions](https://github.com/spatie/opening-hours-go/discussions)

Introduction
------------

With `opening-hours-go` you create a schedule that describes a business' opening hours, which you can query for open or closed on days or specific dates, or use to present the times per day.

A set of opening hours is created by passing in a regular schedule and a list of exceptions.

```
hours, err := openinghours.ParseJSON([]byte(`{
    "monday":    ["09:00-12:00", "13:00-18:00"],
    "tuesday":   ["09:00-12:00", "13:00-18:00"],
    "wednesday": ["09:00-12:00"],
    "thursday":  ["09:00-12:00", "13:00-18:00"],
    "friday":    ["09:00-12:00", "13:00-20:00"],
    "saturday":  ["09:00-12:00", "13:00-16:00"],
    "sunday":    [],
    "exceptions": {
        "2016-11-11": ["09:00-12:00"],
        "2016-12-25": [],
        "01-01": [],
        "12-25": ["09:00-12:00"]
    }
}`))
if err != nil {
    panic(err)
}

now := time.Now()
if current, ok := hours.CurrentOpenRange(now); ok {
    fmt.Println("It's open since", current.Start.Format("Monday 15:04"))
    fmt.Println("It will close at", current.End.Format("Monday 15:04"))
} else {
    next, err := hours.NextOpen(now)
    if err != nil {
        panic(err)
    }
    fmt.Println("It will re-open at", next.Format("Monday 15:04"))
}
```

The full-date Christmas exception takes precedence over the recurring one. Filters take precedence over both.

The package uses `time.Time`, `time.Location` and `time.Duration` rather than PHP date classes. You can also build typed schedules with `New(Config)`. Date filters are Go functions and metadata can be any Go value.

Start with [installation and setup](installation-and-setup), then read [usage](usage). The PHP package keeps its documentation in its README. These pages follow its introduction, installation, usage and value-object sections, with Go examples and explicit behavior differences.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
