PHPackages                             mackrais-organization/working-date-time-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. mackrais-organization/working-date-time-php

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

mackrais-organization/working-date-time-php
===========================================

A PHP library for working date-time calculations that considers working hours, weekends, and holidays.

v1.0.0(1y ago)01MITPHPPHP &gt;=8.3CI passing

Since Mar 14Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/mackrais-organization/working-date-time-php)[ Packagist](https://packagist.org/packages/mackrais-organization/working-date-time-php)[ Docs](https://github.com/mackrais-organization/working-date-time-php)[ GitHub Sponsors](https://github.com/mackrais)[ RSS](/packages/mackrais-organization-working-date-time-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (9)Versions (3)Used By (0)

PHP script Working Date Time
============================

[](#php-script-working-date-time)

[![Scrutinizer Quality Score](https://camo.githubusercontent.com/4d79013f653e3fa42603b6d5b2e94a03a578acb6def96463aa665f3df936b0fe/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d61636b726169732d6f7267616e697a6174696f6e2f776f726b696e672d646174652d74696d652d7068702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/mackrais-organization/working-date-time-php/)[![Build Status](https://camo.githubusercontent.com/50f5ea80f38a3fb21e52b4b34b1b1bbd09c5a0e8885206889e2a220ee5a743ed/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61636b726169732d6f7267616e697a6174696f6e2f776f726b696e672d646174652d74696d652d7068702f63692e79616d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/mackrais-organization/working-date-time-php/actions?query=workflow%3ACI+branch%3Amaster+)[![License](https://camo.githubusercontent.com/e3a78d5402ff1aabf3c57dd195868b84494b66906b6384facdcc4d816e577ac3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d61636b726169732d6f7267616e697a6174696f6e2f776f726b696e672d646174652d74696d652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mackrais-organization/working-date-time-php)[![Latest Stable Version](https://camo.githubusercontent.com/74dbe4a50d3354f1f28e380da9deedbeedd586fd541769adc164e47e1cfa9615/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61636b726169732d6f7267616e697a6174696f6e2f776f726b696e672d646174652d74696d652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mackrais-organization/working-date-time-php)[![Latest Unstable Version](https://camo.githubusercontent.com/915bed8f12b006e7c000f70ef5d87e6334c207b25c9d715eb0b93ad049601e7f/68747470733a2f2f706f7365722e707567782e6f72672f6d61636b726169732d6f7267616e697a6174696f6e2f776f726b696e672d646174652d74696d652d7068702f762f756e737461626c65)](https://packagist.org/packages/mackrais-organization/working-date-time-php)[![CodeCov](https://camo.githubusercontent.com/1bbc0ba941cd6b35d2b98385fe2ad8e98f0455dc1bed7de65c41a5556719b524/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6d61636b726169732d6f7267616e697a6174696f6e2f776f726b696e672d646174652d74696d652d7068702e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/mackrais-organization/working-date-time-php)[![StyleCI](https://camo.githubusercontent.com/4c8f157d76490962c8b23cd0a9214a635916f7eeeccc9ebf142567d61e7fa5e5/68747470733a2f2f7374796c6563692e696f2f7265706f732f3133393732313431362f736869656c643f7374796c653d666c61742d737175617265)](https://styleci.io/repos/139721416)[![Gitter](https://camo.githubusercontent.com/38615bd37fa667fefc3415d970da6c8f0de8796527cb97a89dfc59435f3189bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6769747465722d6a6f696e253230636861742d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://gitter.im/mackrais-organization/working-date-time-php)[![Total Downloads](https://camo.githubusercontent.com/9bcd718c57d56978e3ae22840ee0e88e5c4e6963c05bbbfbbcc9a1c25af7aaa0/68747470733a2f2f706f7365722e707567782e6f72672f6d61636b726169732d6f7267616e697a6174696f6e2f776f726b696e672d646174652d74696d652d7068702f646f776e6c6f616473)](https://packagist.org/packages/mackrais-organization/working-date-time-php)[![Monthly Downloads](https://camo.githubusercontent.com/3fcae32f7f39092f9b52f7f9f88d2e3ba7075af9ae190feb9a5b621bc4503695/68747470733a2f2f706f7365722e707567782e6f72672f6d61636b726169732d6f7267616e697a6174696f6e2f776f726b696e672d646174652d74696d652d7068702f642f6d6f6e74686c79)](https://packagist.org/packages/mackrais-organization/working-date-time-php)[![Daily Downloads](https://camo.githubusercontent.com/909e55b901f5b5d3939813b19906ff974835e24d9540104cf02f3353e9dbf0b3/68747470733a2f2f706f7365722e707567782e6f72672f6d61636b726169732d6f7267616e697a6174696f6e2f776f726b696e672d646174652d74696d652d7068702f642f6461696c79)](https://packagist.org/packages/mackrais-organization/working-date-time-php)

Overview
--------

[](#overview)

The **Working Date Time** PHP library allows you to perform calculations on working hours and business days while skipping weekends and holidays. This can be useful for scheduling tasks, processing business logic that adheres to working hours, and handling delays due to non-working days.

### Features

[](#features)

- Supports custom **start and end working hours**
- Skips **weekends and exception dates (holidays)**
- Supports both **forward and reverse calculations**
- Allows adding days, hours, minutes within **working time only**
- Handles **cross-year transitions** while respecting work schedules
- Efficiently processes **work duration across multiple days**
- Ideal for **workforce scheduling, deadline calculations, and automated task execution**

📌 Table of Contents
-------------------

[](#-table-of-contents)

- [Installation](#installation)
- [How to Use](#how-to-use)
- [Examples](#examples)
    - [Default Usage](docs/example_1_default.md)
    - [Reverse Calculation](docs/example_1_reverse.md)
- [Algorithm Explanation](#algorithm-explanation)
- [License](LICENSE.md)

🛠 Installation
--------------

[](#-installation)

You can install this package via Composer:

```
composer require mackrais/working-date-time
```

Alternatively, you can manually include it in your project.

🚀 How to Use
------------

[](#-how-to-use)

```
$workingDateTime = new \MackRais\DateTime\WorkingDateTime();

// Forward calculation example
$calculatedDate = $workingDateTime
    ->setExceptionDates(['01-01']) // New Year as an exception date
    ->setWeekends(['Sunday', 'Saturday']) // Weekends are Saturday and Sunday
    ->setDateFrom('2024-03-12 10:00:00') // Start date
    ->setStartHourWorkingDay(8)
    ->setStartMinuteWorkingDay(0)
    ->setEndHourWorkingDay(17)
    ->setEndMinuteWorkingDay(0)
    ->setDays(2) // Add 2 working days
    ->setHours(4) // Add 4 working hours
    ->calculate()
    ->format('Y-m-d H:i:s');

// Output: 2024-03-14 14:00:00
```

🔄 Reverse Calculation Example
-----------------------------

[](#-reverse-calculation-example)

```
$workingDateTime = new \MackRais\DateTime\WorkingDateTime();

// Reverse calculation example (subtracting time)
$calculatedDate = $workingDateTime
    ->setExceptionDates(['01-01']) // New Year as an exception date
    ->setWeekends(['Sunday', 'Saturday']) // Weekends
    ->setDateFrom('2024-03-15 10:00:00') // Start date
    ->setStartHourWorkingDay(8)
    ->setStartMinuteWorkingDay(0)
    ->setEndHourWorkingDay(17)
    ->setEndMinuteWorkingDay(0)
    ->setDays(1) // Subtract 1 working day
    ->setHours(3) // Subtract 3 working hours
    ->setMinutes(30) // Subtract 30 minutes
    ->asReverse() // Reverse mode
    ->calculate()
    ->format('Y-m-d H:i:s');

// Output: 2024-03-12 09:30:00
```

📚 Algorithm Explanation
-----------------------

[](#-algorithm-explanation)

The script calculates working time while considering working hours, weekends, and exception dates. The steps are as follows:

### 1️⃣ **Initialize Time Variables**

[](#1️⃣-initialize-time-variables)

- Parse the given `dateFrom` and extract hours, minutes, and seconds.
- Determine `startOfDay` and `endOfDay` based on working hours.

### 2️⃣ **Apply Additions or Subtractions**

[](#2️⃣-apply-additions-or-subtractions)

- If adding time, increment the date by the provided days/hours while skipping weekends and holidays.
- If subtracting time (reverse mode), decrement accordingly while respecting work hours.

### 3️⃣ **Handle Working Hour Limits**

[](#3️⃣-handle-working-hour-limits)

- If the added/subtracted time crosses the `endOfDay`, carry over to the next/previous working day.
- If the computed time lands on a weekend or exception date, shift forward or backward accordingly.

### 4️⃣ **Edge Case Handling**

[](#4️⃣-edge-case-handling)

- **Cross-Year Transitions**: If the date range includes New Year or other holidays, the script ensures calculations account for them.
- **Multiple Non-Working Days**: If several holidays or weekends occur consecutively, the script intelligently skips them.

🏆 Use Cases
-----------

[](#-use-cases)

- **Task Scheduling**: Automate scheduling tasks that should only execute during business hours.
- **Deadline Calculations**: Compute deadlines that exclude weekends and holidays.
- **Workforce Management**: Calculate shift times while considering off days and public holidays.
- **Financial Calculations**: Determine transaction processing dates based on business hours.

📜 License
---------

[](#-license)

**working-date-time-php** is released under the MIT License. See the bundled [`LICENSE.md`](LICENSE.md) for details.

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance60

Regular maintenance activity

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

420d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/488beefc5336c7cda0467a3c200e1d1d9ae6fe68639549b6b19179c8db74e3c7?d=identicon)[MackRais](/maintainers/MackRais)

---

Top Contributors

[![mackrais](https://avatars.githubusercontent.com/u/8103057?v=4)](https://github.com/mackrais "mackrais (7 commits)")

---

Tags

business-dayscalcilator-working-datecalcilator-working-dayscalcilator-working-timecalculationcalculatordatetimephpphp-scriptphp-working-date-timephp7working-dateworking-timedatetimetimedatecalendarTask Schedulerbusiness hoursbusiness daysnon-working daysworking-timeworking-date-timework-scheduleshift-managementweekends

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mackrais-organization-working-date-time-php/health.svg)

```
[![Health](https://phpackages.com/badges/mackrais-organization-working-date-time-php/health.svg)](https://phpackages.com/packages/mackrais-organization-working-date-time-php)
```

###  Alternatives

[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)[brick/date-time

Date and time library

3623.3M60](/packages/brick-date-time)[tplaner/when

Date/Calendar recursion library.

5261.0M5](/packages/tplaner-when)[kartik-v/php-date-formatter

A Javascript datetime formatting and manipulation library using PHP date-time formats.

461.5M3](/packages/kartik-v-php-date-formatter)[dater/dater

Compact PHP library for working with date/time in different formats &amp; timezones.

14282.3k](/packages/dater-dater)

PHPackages © 2026

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