PHPackages                             letsjump/workday-helper-php - 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. letsjump/workday-helper-php

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

letsjump/workday-helper-php
===========================

Count work days and list holiday events in a range of dates with PHP taking care of public holidays and other custom closing days.

v1.0.0(5y ago)619.5k↓36%1MITPHPPHP &gt;=5.6

Since Feb 15Pushed 4y ago1 watchersCompare

[ Source](https://github.com/letsjump/workday-helper-php)[ Packagist](https://packagist.org/packages/letsjump/workday-helper-php)[ RSS](/packages/letsjump-workday-helper-php/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependenciesVersions (2)Used By (0)

[![Packagist Downloads](https://camo.githubusercontent.com/3168459a349ad6802b46fdd693282f2657ee2a509161923113148abafa6a5d6b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6574736a756d702f776f726b6461792d68656c7065722d706870)](https://packagist.org/packages/letsjump/workday-helper-php/stats)[![Packagist License](https://camo.githubusercontent.com/0aff089082a12e36b0018059fc1365e16fb9723f0182bc9d1e0152727b6572b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6574736a756d702f776f726b6461792d68656c7065722d706870)](https://github.com/letsjump/workday-helper-php/blob/main/LICENSE)[![Packagist Version](https://camo.githubusercontent.com/4fd3ab5685affdf6dcc3d71cf8d4fda0a832ba04d57ae9716052b24b6dfa13ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6574736a756d702f776f726b6461792d68656c7065722d706870)](https://packagist.org/packages/letsjump/workday-helper-php#v1.0.0)[![GitHub issues](https://camo.githubusercontent.com/ec3da32278452e4ee8896a336081a254dd0334abc5165c8069aff5309ed245c0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6c6574736a756d702f776f726b6461792d68656c7065722d706870)](https://github.com/letsjump/workday-helper-php/issues)[![Packagist PHP Version Support](https://camo.githubusercontent.com/30d1576002405c4b9452a27087f839dd509ed00bbabe09ba4859ed006cebdabd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c6574736a756d702f776f726b6461792d68656c7065722d706870)](https://github.com/letsjump/workday-helper-php/issues)[![Scrutinizer code quality (GitHub/Bitbucket)](https://camo.githubusercontent.com/3e88a8122e9f5d9413fb46fdc7bda84bc407e10116b84cdd9af1466e8dc43689/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f6c6574736a756d702f776f726b6461792d68656c7065722d706870)](https://scrutinizer-ci.com/g/letsjump/workday-helper-php/)

WorkdayHelper
=============

[](#workdayhelper)

Count workdays and list holiday events in a range of dates with PHP taking care of public holidays and other custom closing days.

Inspired by Massimo Simonini getWorkdays() Gist. @see

Benefits and features:

- you can specify a range of working days in a week (from Monday to Sunday);
- you can add custom holidays and business closures, for example as a result of a database query;
- it returns a calendar of holidays for that specific range of dates;
- you can use your custom recursive holiday calendar (see `$publicHolidays`);
- it takes care of the timezone of your application;
- it automatically calculates Easter, and Easter mondays taking care of the timezone (requires PHP with `ext-calendar`);

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

[](#requirements)

PHP 5.6.0 and later

Composer
--------

[](#composer)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

`composer require --prefer-dist letsjump/workday-helper-php`

or add

`"letsjump/workday-helper-php": "~1.0.0"`

to the `require` section of your composer.json.

Manual Installation
-------------------

[](#manual-installation)

If you do not wish to use Composer, you can download the [latest release](https://github.com/letsjump/workday-helper-php).

```
require_once('/path/to/workday-helper-php/WorkdayHelper.php');
```

Dependencies
------------

[](#dependencies)

### PHP ext-calendar

[](#php-ext-calendar)

To automatically calculate Easter dates, you have to compile PHP with `--enable-calendar`. See [ext-calendar](https://www.php.net/manual/en/book.calendar.php). You can refer to [this Stack Overflow question](https://stackoverflow.com/questions/5297894/fatal-error-call-to-undefined-function-easter-date/51609625) if you are in a Docker environment.

If your PHP isn't compiled with ext-calendar and if you cannot compile it, please set `$calculateEaster` to `false` otherwhise WorkingdayHelper will throw an exception.

Usage:
------

[](#usage)

1. Count the days worked in January while working from Monday to Friday, taking care of public holidays:

```
use letsjump\workdayHelper\WorkdayHelper;

$closingDays                 = new WorkdayHelper('2021-01-01', '2021-01-31');
$closingDays->workingDays    = [1, 2, 3, 4, 5];

echo $closingDays->getWorkdays(); // (19 days)
```

2. count the day worked in april while working Monday, Wednesday and Friday, taking care of public holidays:

```
$closingDays                 = new WorkdayHelper('2021-04-01', '2021-04-30');
$closingDays->workingDays    = [1, 3, 5];
echo $closingDays->getWorkdays(); // (12 days)
```

3. Add a strike to the custom closing days

```
$closingDays                 = new WorkdayHelper('2021-01-01', '2021-01-31');
$closingDays->workingDays          = [1, 2, 3, 4, 5];
$closingDays->customClosing = [
     [
         'date'    => '2021-01-18',
         'event'   => 'Strike!',
         'options' => [
             'employee_id'        => 345,
             'htmlClass' => 'deep-purple'
         ]
     ],
];
echo $closingDays->getWorkdays(); // (18 days)
```

4. Get the calendar with all the closing days for a specific date interval

```
$closingDays                 = new WorkdayHelper('2021-01-01', '2021-12-31');
$closingDays->workingDays          = [0, 1, 2, 3, 4, 5, 6]; // don't forget to set every day of the week!

```

[![Gii module](docs/assets/images/calendar.jpg)](docs/assets/images/calendar.jpg)

### Add custom closings

[](#add-custom-closings)

Custom closure is an array of events. Each event is an array with this configuration:

keyvaluemandatorydatedate in Y-m-d formatyeseventa string representing the name of the closingyesoptionsa string or an array passed as is to the holiday calendar. It may contain information such as event\_id, user\_id, html attributes, etc.. Please remember that data are passed as they are so, to prevent malicious injection attacks, consider the use of a string purifier functionno**example**

```
$myInstantatedClass->customClosing = [
         [
             'date'  => '2021-01-10',
             'event' => 'Chiusura per ferie'
         ],
         [
             'date'    => '2021-01-05',
             'event'   => 'Strike!',
             'options' => [
                  'id'        => 345,
                  'htmlClass' => 'green'
             ]
         ],
          ...
];
```

### Replace the default recursive holiday calendar

[](#replace-the-default-recursive-holiday-calendar)

The default recursive holiday calendar is an array of events. Each event is an array with this configuration:

keyvaluemandatorym-dthe date must be in m-d formatyeseventa string representing the name of the holidayyesoptionsa string or an array passed as is to the holiday calendar. It may contain information such as event\_id, user\_id, html attributes, etc.. Please remember that data are passed as they are so, to prevent malicious injection attacks, consider the use of a string purifier functionno**example**

```
$myInstantatedClass->publicHolidays = [
         [
             'm-d'  => '12-25',
             'event' => 'Christmas'
         ],
         [
             'm-d'    => '12-26',
             'event'   => 'Boxing day',
             'options' => [
                  'id'        => 345,
                  'htmlClass' => 'green'
             ]
         ],
          ...
];
```

### Holiday calendar

[](#holiday-calendar)

The holiday calendar returns a list of holidays for the working days in the given date range. So if you want to retrive *all the closing days* in that date range you should set all the days of the week into the $workingDays Array E.G. $myWorkDay-&gt;workingDays\[0,1,2,3,4,5,6\].

The output is an array of events. Each array has the unix timestamp of the holiday as key and contains:

keyvalueunixTimestampthe unix timestamp of the eventdatethe readable date of the event (you can format it with the parameter `$outputFormat`eventthe name of the event typeoptionsa string or an array of user custom optionsExample

```
      [
         [1609455600] => [
             [unixTimestamp] => 1609455600,
             [date] => 2021-01-01, # control the format with $outputFormat property
             [event] => Capodanno, # description of the event
             [type] => public, #public / custom
             [options] => # custom option passed by the $customClosing or the $publicHolidays Array
         ],
         ...
      ]
```

Side notes
----------

[](#side-notes)

The recursive holiday and the default date format are localized for Italy. I know it's not the right way to work, but I need to quickly develop an application for a customer. If you want to use your localization, please refer to *Replace the default recursive holiday calendar*. If you plan to use intensively in your application, you may extend the base class and configure there the basic properties.

Please report any bug or whishes into the apposite [issue tracker](https://github.com/letsjump/workday-helper-php/issues)

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

1954d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/284998?v=4)[Gianpaolo Scrigna](/maintainers/letsjump)[@letsjump](https://github.com/letsjump)

---

Top Contributors

[![letsjump](https://avatars.githubusercontent.com/u/284998?v=4)](https://github.com/letsjump "letsjump (10 commits)")

---

Tags

businesscalendarholidaysemployeeworkdaysworkShiftlist holidays

### Embed Badge

![Health badge](/badges/letsjump-workday-helper-php/health.svg)

```
[![Health](https://phpackages.com/badges/letsjump-workday-helper-php/health.svg)](https://phpackages.com/packages/letsjump-workday-helper-php)
```

###  Alternatives

[umulmrum/holiday

A PHP library to compute holidays. It's something :-)

92371.2k1](/packages/umulmrum-holiday)[holidayapi/holidayapi-php

Official PHP library for Holiday API

35229.3k1](/packages/holidayapi-holidayapi-php)[aeon-php/calendar-holidays

Holidays calendar abstraction layer for Aeon Time management framework

14214.0k3](/packages/aeon-php-calendar-holidays)[aeon-php/business-hours

Abstraction allowing to define and check against business hours

10143.5k](/packages/aeon-php-business-hours)

PHPackages © 2026

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