PHPackages                             octava/opening-hours - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. octava/opening-hours

ActiveLibrary

octava/opening-hours
====================

A helper to query and format a set of opening hours, clone of spatie/opening-hours

1.0.3(9y ago)0786MITPHPPHP &gt;=5.5.9

Since Oct 13Pushed 9y ago1 watchersCompare

[ Source](https://github.com/octava/opening-hours)[ Packagist](https://packagist.org/packages/octava/opening-hours)[ Docs](https://github.com/spatie/opening-hours)[ RSS](/packages/octava-opening-hours/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

A helper to query and format a set of opening hours
===================================================

[](#a-helper-to-query-and-format-a-set-of-opening-hours)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3d8c0b3d9181f4357f8588d1767b0e94a4945466ad6bce261ee9adbb25f7f52d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6f70656e696e672d686f7572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/opening-hours)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/fee08764fa0e972546c7ac629436f09eeb15a8da5f924cf430e35440e27a51dc/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f6f70656e696e672d686f7572732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/opening-hours)[![SensioLabsInsight](https://camo.githubusercontent.com/242152590c60ff182ad6b98da618a876dd05b43425980b51bbf86de2cde2ecff/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f30383233343762342d613366362d346237372d623861312d3661363464353032333266372e7376673f7374796c653d666c61742d737175617265)](https://insight.sensiolabs.com/projects/082347b4-a3f6-4b77-b8a1-6a64d50232f7)[![Quality Score](https://camo.githubusercontent.com/443c64d61f1fc0c95682cc5a50d73dff4dbf54953df54cf4613a02237f5efcb8/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f6f70656e696e672d686f7572732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/opening-hours)[![StyleCI](https://camo.githubusercontent.com/a7f3c0efdbce74151028848d1691cc6afb5d5c487485d3efb793d428ed348467/68747470733a2f2f7374796c6563692e696f2f7265706f732f36393336383130342f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/69368104)[![Total Downloads](https://camo.githubusercontent.com/fa07fee6c25b9b3d63267136d1187f4552430614f9d75561b4bbf51fcca6ea1b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6f70656e696e672d686f7572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/opening-hours)

With `spatie/opening-hours` you create an object 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.

```
$openingHours = OpeningHours::create([
    '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' => [],
    ],
]);
```

The object can be queried for a day in the week, which will return a result based on the regular schedule:

```
// Open on Mondays:
$openingHours->isOpenOn('monday'); // true

// Closed on Sundays:
$openingHours->isOpenOn('sunday'); // false
```

It can also be queried for a specific date and time:

```
// Closed because it's after hours:
$openingHours->isOpenAt(new DateTime('2016-09-26 19:00:00')); // false

// Closed because Christmas was set as an exception
$openingHours->isOpenAt(new DateTime('2016-12-25')); // false
```

It can also return arrays of opening hours for a week or a day:

```
// OpeningHoursForDay object for the regular schedule
$openingHours->forDay('monday');

// OpeningHoursForDay[] for the regular schedule, keyed by day name
$openingHours->forWeek();

// OpeningHoursForDay object for a specific day
$openingHours->forDate(new DateTime('2016-12-25'));

// OpeningHoursForDay[] of all exceptions, keyed by date
$openingHours->exceptions();
```

Read the usage section for the full api.

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Postcardware
------------

[](#postcardware)

You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

The best postcards will get published on the open source page on our website.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/opening-hours
```

Usage
-----

[](#usage)

The package should only be used through the `OpeningHours` class. There are also three value object classes used throughout, `Time`, which represents a single time, `TimeRange`, which represents a period with a start and an end, and `openingHoursForDay`, which represents a set of `TimeRange`s which can't overlap.

### `Spatie\OpeningHours\OpeningHours`

[](#spatieopeninghoursopeninghours)

#### `OpeningHours::create(array $data): Spatie\OpeningHours\OpeningHours`

[](#openinghourscreatearray-data-spatieopeninghoursopeninghours)

Static factory method to fill the set of opening hours.

```
$openingHours = OpeningHours::create([
    'monday' => ['09:00-12:00', '13:00-18:00'],
    // ...
]);
```

Not all days are mandatory, if a day is missing, it will be set as closed.

#### `OpeningHours::fill(array $data): Spatie\OpeningHours\OpeningHours`

[](#openinghoursfillarray-data-spatieopeninghoursopeninghours)

The same as `create`, but non-static.

```
$openingHours = (new OpeningHours)->fill([
    'monday' => ['09:00-12:00', '13:00-18:00'],
    // ...
]);
```

#### `OpeningHours::forWeek(): Spatie\OpeningHours\OpeningHoursForDay[]`

[](#openinghoursforweek-spatieopeninghoursopeninghoursforday)

Returns an array of `OpeningHoursForDay` objects for a regular week.

```
$openingHours->forWeek();
```

#### `OpeningHours::forDay(string $day): Spatie\OpeningHours\OpeningHoursForDay`

[](#openinghoursfordaystring-day-spatieopeninghoursopeninghoursforday)

Returns an `OpeningHoursForDay` object for a regular day. A day is lowercase string of the english day name.

```
$openingHours->forDay('monday');
```

#### `OpeningHours::forDate(DateTime $dateTime): Spatie\OpeningHours\OpeningHoursForDay`

[](#openinghoursfordatedatetime-datetime-spatieopeninghoursopeninghoursforday)

Returns an `OpeningHoursForDay` object for a specific date. It looks for an exception on that day, and otherwise it returns the opening hours based on the regular schedule.

```
$openingHours->forDate(new DateTime('2016-12-25'));
```

#### `OpeningHours::exceptions(): Spatie\OpeningHours\OpeningHoursForDay[]`

[](#openinghoursexceptions-spatieopeninghoursopeninghoursforday)

Returns an array of all `OpeningHoursForDay` objects for exceptions, keyed by a `Y-m-d` date string.

```
$openingHours->exceptions();
```

#### `OpeningHours::isOpenOn(string $day): bool`

[](#openinghoursisopenonstring-day-bool)

Checks if the business is op on a day in the regular schedule.

```
$openingHours->isOpenOn('saturday');
```

#### `OpeningHours::isClosedOn(string $day): bool`

[](#openinghoursisclosedonstring-day-bool)

Checks if the business is closed on a day in the regular schedule.

```
$openingHours->isClosedOn('sunday');
```

#### `OpeningHours::isOpenAt(DateTime $dateTime): bool`

[](#openinghoursisopenatdatetime-datetime-bool)

Checks if the business is open on a specific day, at a specific time.

```
$openingHours->isOpenAt(new DateTime('2016-26-09 20:00'));
```

#### `OpeningHours::isClosedAt(DateTime $dateTime): bool`

[](#openinghoursisclosedatdatetime-datetime-bool)

Checks if the business is closed on a specific day, at a specific time.

```
$openingHours->isClosedAt(new DateTime('2016-26-09 20:00'));
```

#### `OpeningHours::isOpen(): bool`

[](#openinghoursisopen-bool)

Checks if the business is open right now.

```
$openingHours->isOpen();
```

#### `OpeningHours::isClosed(): bool`

[](#openinghoursisclosed-bool)

Checks if the business is closed right now.

```
$openingHours->isClosed();
```

### `Spatie\OpeningHours\OpeningHoursForDay`

[](#spatieopeninghoursopeninghoursforday)

This class is meant as read-only. It implements `ArrayAccess`, `Countable` and `IteratorAggregate` so you can process the list of `TimeRange`s in an array-like way.

### `Spatie\OpeningHours\TimeRange`

[](#spatieopeninghourstimerange)

Value object describing a period with a start and an end time. Can be casted to a string in a `H:i-H:i` format.

### `Spatie\OpeningHours\Time`

[](#spatieopeninghourstime)

Value object describing a single time. Can be casted to a string in a `H:i` format.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [All Contributors](../../contributors)

About Spatie
------------

[](#about-spatie)

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 65% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3498d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5ea149a698d7b757dcacf1ee59c13ba2aea3335b009fd5e4ae6af68c670c579?d=identicon)[TheRatG](/maintainers/TheRatG)

---

Top Contributors

[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (26 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (11 commits)")[![bobbybouwmann](https://avatars.githubusercontent.com/u/5872362?v=4)](https://github.com/bobbybouwmann "bobbybouwmann (1 commits)")[![jeromegamez](https://avatars.githubusercontent.com/u/67554?v=4)](https://github.com/jeromegamez "jeromegamez (1 commits)")[![mitchellvanw](https://avatars.githubusercontent.com/u/3061428?v=4)](https://github.com/mitchellvanw "mitchellvanw (1 commits)")

---

Tags

spatieschedulehoursopeningopening-hoursoctava

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/octava-opening-hours/health.svg)

```
[![Health](https://phpackages.com/badges/octava-opening-hours/health.svg)](https://phpackages.com/packages/octava-opening-hours)
```

###  Alternatives

[spatie/opening-hours

A helper to query and format a set of opening hours

1.7k5.3M30](/packages/spatie-opening-hours)[spatie/laravel-backup

A Laravel package to backup your application

6.0k21.8M191](/packages/spatie-laravel-backup)[spatie/image-optimizer

Easily optimize images using PHP

2.9k71.3M109](/packages/spatie-image-optimizer)[spatie/laravel-query-builder

Easily build Eloquent queries from API requests

4.4k26.9M220](/packages/spatie-laravel-query-builder)[spatie/laravel-google-calendar

Manage events on a Google Calendar

1.4k1.5M21](/packages/spatie-laravel-google-calendar)[spatie/laravel-translatable

A trait to make an Eloquent model hold translations

2.4k23.0M413](/packages/spatie-laravel-translatable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
