PHPackages                             florianv/business - 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. florianv/business

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

florianv/business
=================

DateTime calculations in business hours

v2.0.0(3y ago)359775.9k↓22.9%25[32 issues](https://github.com/florianv/business/issues)1MITPHPPHP &gt;=8.0

Since Jun 3Pushed 3y ago7 watchersCompare

[ Source](https://github.com/florianv/business)[ Packagist](https://packagist.org/packages/florianv/business)[ Docs](https://github.com/florianv/business)[ RSS](/packages/florianv-business/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (9)Used By (1)

Business [![Build status](https://camo.githubusercontent.com/c060a9d34fe50ef7bcd28248596f3951b696ff3055f8cf853d58be43e3ac0a88/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f666c6f7269616e762f627573696e6573732e7376673f7374796c653d666c6174)](https://travis-ci.org/florianv/business) [![Version](https://camo.githubusercontent.com/7394e4f07aa141f56b5f0796ef67bde8294d6c21eba64c6489f5b996b4772286/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666c6f7269616e762f627573696e6573732e7376673f7374796c653d666c6174)](https://packagist.org/packages/florianv/business) [![PHP Version](https://camo.githubusercontent.com/fc7971007087f4149e530d0b858341f06552ae4ee39d71f39e78f7372c9a7bf4/687474703a2f2f696d672e736869656c64732e696f2f62616467652f7068702d352e342b2d6666363962342e737667)](https://packagist.org/packages/florianv/business)
===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#business---)

> DateTime calculations in business hours

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

[](#installation)

```
$ composer require florianv/business
```

Usage
-----

[](#usage)

First you need to configure your business schedule:

```
use Business\SpecialDay;
use Business\Day;
use Business\Days;
use Business\Business;
use Business\Holidays;
use Business\DateRange;

// Opening hours for each week day. If not specified, it is considered closed
$days = [
    // Standard days with fixed opening hours
    new Day(Days::MONDAY, [['09:00', '13:00'], ['2pm', '5 PM']]),
    new Day(Days::TUESDAY, [['9 AM', '5 PM']]),
    new Day(Days::WEDNESDAY, [['10:00', '13:00'], ['14:00', '17:00']]),
    new Day(Days::THURSDAY, [['10 AM', '5 PM']]),

    // Special day with dynamic opening hours depending on the date
    new SpecialDay(Days::FRIDAY, function (\DateTime $date) {
        if ('2015-05-29' === $date->format('Y-m-d')) {
            return [['9 AM', '12:00']];
        }

        return [['9 AM', '5 PM']];
    }),
];

// Optional holiday dates
$holidays = new Holidays([
    new \DateTime('2015-01-01'),
    new \DateTime('2015-01-02'),
    new DateRange(new \DateTime('2015-07-08'), new \DateTime('2015-07-11')),
]);

// Optional business timezone
$timezone = new \DateTimeZone('Europe/Paris');

// Create a new Business instance
$business = new Business($days, $holidays, $timezone);
```

### Methods

[](#methods)

##### within() - Tells if a date is within business hours

[](#within---tells-if-a-date-is-within-business-hours)

```
$bool = $business->within(new \DateTime('2015-05-11 10:00'));
```

##### timeline() - Returns a timeline of business dates

[](#timeline---returns-a-timeline-of-business-dates)

```
$start = new \DateTime('2015-05-11 10:00');
$end = new \DateTime('2015-05-14 10:00');
$interval = new \DateInterval('P1D');

$dates = $business->timeline($start, $end, $interval);
```

##### closest() - Returns the closest business date from a given date

[](#closest---returns-the-closest-business-date-from-a-given-date)

```
// After that date (including it)
$nextDate = $business->closest(new \DateTime('2015-05-11 10:00'));

// Before that date (including it)
$lastDate = $business->closest(new \DateTime('2015-05-11 10:00'), Business::CLOSEST_LAST);
```

### Serialization

[](#serialization)

#### PHP serialization

[](#php-serialization)

The `Business` class can be serialized so it can be stored for later reuse:

```
$serialized = serialize($business);
$business = unserialize($serialized);
```

If you use `SpecialDay` instances, you need to install the `jeremeamia/superclosure` library providing closure serialization:

```
$ composer require jeremeamia/superclosure
```

#### JSON serialization

[](#json-serialization)

All classes can be encoded to JSON

```
$json = json_encode($business);
```

The `SpecialDay` instances require a context in order extract the data from the callable. This is automatically set to `new \DateTime('now')` for `json_encode()` call only.

License
-------

[](#license)

[MIT](https://github.com/florianv/business/blob/master/LICENSE)

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity56

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 60.5% 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 ~428 days

Recently: every ~640 days

Total

7

Last Release

1435d ago

Major Versions

v1.3.0 → v2.0.02022-06-13

PHP version history (2 changes)v1.0.0PHP &gt;=5.4

v2.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1586668?v=4)[Florian Voutzinos](/maintainers/florianv)[@florianv](https://github.com/florianv)

---

Top Contributors

[![florianv](https://avatars.githubusercontent.com/u/1586668?v=4)](https://github.com/florianv "florianv (23 commits)")[![dragosprotung](https://avatars.githubusercontent.com/u/1081073?v=4)](https://github.com/dragosprotung "dragosprotung (3 commits)")[![sagikazarmark](https://avatars.githubusercontent.com/u/1226384?v=4)](https://github.com/sagikazarmark "sagikazarmark (3 commits)")[![raphaelstolt](https://avatars.githubusercontent.com/u/48225?v=4)](https://github.com/raphaelstolt "raphaelstolt (2 commits)")[![ceeram](https://avatars.githubusercontent.com/u/111448?v=4)](https://github.com/ceeram "ceeram (2 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")[![Bilge](https://avatars.githubusercontent.com/u/470626?v=4)](https://github.com/Bilge "Bilge (1 commits)")[![florianklockenkemper](https://avatars.githubusercontent.com/u/13658082?v=4)](https://github.com/florianklockenkemper "florianklockenkemper (1 commits)")[![pyrech](https://avatars.githubusercontent.com/u/2021641?v=4)](https://github.com/pyrech "pyrech (1 commits)")[![bendavies](https://avatars.githubusercontent.com/u/625392?v=4)](https://github.com/bendavies "bendavies (1 commits)")

---

Tags

business-hoursdateopening-hoursphpbusinesstimedateschedulehour

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/florianv-business/health.svg)

```
[![Health](https://phpackages.com/badges/florianv-business/health.svg)](https://phpackages.com/packages/florianv-business)
```

###  Alternatives

[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6308.9M39](/packages/knplabs-knp-time-bundle)[brick/date-time

Date and time library

3623.3M61](/packages/brick-date-time)[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)[tplaner/when

Date/Calendar recursion library.

5261.0M5](/packages/tplaner-when)[kartik-v/yii2-date-range

An advanced Yii 2 date range picker input for based on bootstrap-daterangepicker plugin.

894.4M42](/packages/kartik-v-yii2-date-range)

PHPackages © 2026

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