PHPackages                             sourcebox/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sourcebox/opening-hours

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sourcebox/opening-hours
=======================

Check opening hours

v1.0.0(9y ago)6406[1 issues](https://github.com/veloxy/opening-hours/issues)MITPHP

Since Oct 25Pushed 7y ago2 watchersCompare

[ Source](https://github.com/veloxy/opening-hours)[ Packagist](https://packagist.org/packages/sourcebox/opening-hours)[ RSS](/packages/sourcebox-opening-hours/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Opening Hours
=============

[](#opening-hours)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/185ff99388fc878cc8c9310df605328484af7194130edc5d770c3672c90d203b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f76656c6f78792f6f70656e696e672d686f7572732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/veloxy/opening-hours)[![SensioLabs Insight](https://camo.githubusercontent.com/bf8a547bc19878af3478abeb5f007532f8db084851ee5fd86fc62a1c4a2e5491/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f37643735373836352d353833352d343134632d393539312d3036636535306262313561372e7376673f6d61784167653d33363030267374796c653d666c61742d737175617265)](https://insight.sensiolabs.com/projects/7d757865-5835-414c-9591-06ce50bb15a7)[![StyleCI](https://camo.githubusercontent.com/37fda1b93e81490e3dd94bca4d25610aebba1d68b205e11512c1d9d4684485dc/68747470733a2f2f7374796c6563692e696f2f7265706f732f37303734333133372f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/70743137)[![Coverage Status](https://camo.githubusercontent.com/2fdf63677a9800a7b88c9573e9f48722617ef1a008ab6e6eac1934739e4f3cf2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f76656c6f78792f6f70656e696e672d686f7572732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/veloxy/opening-hours/code-structure)

This is a small library that helps you do several checks on opening hours.

Requirements
------------

[](#requirements)

- PHP 7.0+

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

[](#installation)

You can install this library using composer, note that it's still in development and may or may not change drastically before the first version is released.

```
composer require sourcebox/opening-hours

```

Quick Usage
-----------

[](#quick-usage)

You can easily figure out the usage by checking out the tests, but here's a quick example:

### Create a TimeTable

[](#create-a-timetable)

A TimeTable contains your opening hours, it consists of an array of days that each have a set of TimePeriods. A day that doesn't have time periods or a day that doesn't exist in the time table is considered a closed day.

```
$timeTable = new TimeTable([
   new Day(Day::MONDAY, [
       new TimePeriod('08:00', '12:00'),
       new TimePeriod('13:00', '17:00'),
   ]),
   new Day(Day::TUESDAY, [
       new TimePeriod('08:00', '12:00'),
       new TimePeriod('13:00', '17:00'),
   ]),
   new Day(Day::WEDNESDAY, [
       new TimePeriod('08:00', '12:00'),
       new TimePeriod('13:00', '17:00'),
   ]),
   new Day(Day::THURSDAY, [
       new TimePeriod('08:00', '12:00'),
       new TimePeriod('13:00', '17:00'),
   ]),
   new Day(Day::FRIDAY, [
       new TimePeriod('08:00', '12:00'),
       new TimePeriod('13:00', '17:00'),
   ]),
   new Day(Day::SATURDAY, [
       new TimePeriod('08:00', '12:00'),
   ]),
]);

$checker = new OpeningHourChecker($timeTable);
```

The timetable is passed to the opening hour checker so we can start checking stuff.

### Basic checks

[](#basic-checks)

The OpeningHourChecker consists of a few basic checks.

#### Check if it's open on a certain day.

[](#check-if-its-open-on-a-certain-day)

This is a very simple check, only checks if there are time periods for the given day.

```
$checker->isOpenOn(Day::TUESDAY); // true
$checker->isClosedOn(Day::TUESDAY); // false
```

#### Check if it's open on a certain date and time

[](#check-if-its-open-on-a-certain-date-and-time)

This check will check the time periods for a given day and time.

```
$checker->isOpenAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2016-10-10 10:00:00'))); // returns true
$checker->isClosedAt(\DateTime::createFromFormat('Y-m-d H:i:s', '2016-10-10 10:00:00'))); // returns false
```

#### Overrides

[](#overrides)

Overrides are basically exceptions to the timetable. There's two types of overrides, includes and excludes. Include overrides are dates that are included, exclude overrides are dates that are excluded.

There are currently two override classes included.

##### Example

[](#example)

This example adds christmas date as an exclusion override, which means that christmas day is excluded from the timetable. This is handy when you want your store to be closed on certain dates.

```
$dateOverride = new DateOverride($christmasDateTime);
$dateOverride->setType(OverrideInterface::TYPE_EXCLUDE);

$openingHourChecker->addOverride($dateOverride);
$openingHourChecker->isOpenAt($christmasDateTime); // return false
```

The reverse is also possible, say you want to open all day on black friday, regardless of opening hours. You'd use the same `DateOverride` but set the type to `TYPE_INCLUDE`. Not that the overrides prioritize excludes over includes.

There's also a DatePeriodOverride, which does the same as the DateOverride but for a period.

```
$holidayPeriodStart = \DateTime::createFromFormat('Y-m-d H:i:s', '2017-01-01 00:00:00', $timezone);
$holidayPeriodEnd = \DateTime::createFromFormat('Y-m-d H:i:s', '2017-01-10 00:00:00', $timezone);
$holidayPeriod = new DatePeriodOverride($holidayPeriodStart, $holidayPeriodEnd);
$holidayPeriod->setType(OverrideInterface::TYPE_EXCLUDE);

$openingHourChecker->addOverride($holidayPeriod);
```

In this example, store is closed from `$holidayPeriodStart` until `$holidayPeriodEnd`.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

3536d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/491675?v=4)[Kevin Vandenborne](/maintainers/veloxy)[@veloxy](https://github.com/veloxy)

---

Top Contributors

[![veloxy](https://avatars.githubusercontent.com/u/491675?v=4)](https://github.com/veloxy "veloxy (50 commits)")

---

Tags

libraryopening-hoursphp

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[corneltek/actionkit

181.5k](/packages/corneltek-actionkit)

PHPackages © 2026

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