{"id":19974403,"url":"https://github.com/mackrais-organization/working-date-time-php","last_synced_at":"2025-07-18T02:37:36.097Z","repository":{"id":143665633,"uuid":"139721416","full_name":"mackrais-organization/working-date-time-php","owner":"mackrais-organization","description":"The script counts the working hour. For example, you need to make a newsletter only during working hours and days. Or work out a calendar of working year taking into account all details.","archived":false,"fork":false,"pushed_at":"2019-02-19T14:42:17.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-12T09:42:39.485Z","etag":null,"topics":["business-days","calcilator-working-date","calcilator-working-days","calcilator-working-time","calculation","calculator","datetime","php","php-script","php-working-date-time","php7","working-date","working-time"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mackrais-organization.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-04T12:49:10.000Z","updated_at":"2019-02-19T14:42:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"c9945ae8-212c-4765-abfa-c7372e8f1de0","html_url":"https://github.com/mackrais-organization/working-date-time-php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackrais-organization%2Fworking-date-time-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackrais-organization%2Fworking-date-time-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackrais-organization%2Fworking-date-time-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackrais-organization%2Fworking-date-time-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mackrais-organization","download_url":"https://codeload.github.com/mackrais-organization/working-date-time-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241411428,"owners_count":19958746,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["business-days","calcilator-working-date","calcilator-working-days","calcilator-working-time","calculation","calculator","datetime","php","php-script","php-working-date-time","php7","working-date","working-time"],"created_at":"2024-11-13T03:14:55.908Z","updated_at":"2025-07-18T02:37:36.085Z","avatar_url":"https://github.com/mackrais-organization.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP script Working Date Time\n\n[![Scrutinizer Quality Score](https://img.shields.io/scrutinizer/g/mackrais-organization/working-date-time-php.svg?style=flat-square)](https://scrutinizer-ci.com/g/mackrais-organization/working-date-time-php/)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/mackrais-organization/working-date-time-php/ci.yaml?branch=master\u0026style=flat-square)](https://github.com/mackrais-organization/working-date-time-php/actions?query=workflow%3ACI+branch%3Amaster+)\n[![License](https://img.shields.io/packagist/l/mackrais-organization/working-date-time-php.svg?style=flat-square)](https://packagist.org/packages/mackrais-organization/working-date-time-php)\n[![Latest Stable Version](https://img.shields.io/packagist/v/mackrais-organization/working-date-time-php.svg?style=flat-square)](https://packagist.org/packages/mackrais-organization/working-date-time-php)\n[![Latest Unstable Version](https://poser.pugx.org/mackrais-organization/working-date-time-php/v/unstable)](https://packagist.org/packages/mackrais-organization/working-date-time-php)\n[![CodeCov](https://img.shields.io/codecov/c/github/mackrais-organization/working-date-time-php.svg?style=flat-square)](https://codecov.io/github/mackrais-organization/working-date-time-php)\n[![StyleCI](https://styleci.io/repos/139721416/shield?style=flat-square)](https://styleci.io/repos/139721416)\n[![Gitter](https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg?style=flat-square)](https://gitter.im/mackrais-organization/working-date-time-php)\n[![Total Downloads](https://poser.pugx.org/mackrais-organization/working-date-time-php/downloads)](https://packagist.org/packages/mackrais-organization/working-date-time-php)\n[![Monthly Downloads](https://poser.pugx.org/mackrais-organization/working-date-time-php/d/monthly)](https://packagist.org/packages/mackrais-organization/working-date-time-php)\n[![Daily Downloads](https://poser.pugx.org/mackrais-organization/working-date-time-php/d/daily)](https://packagist.org/packages/mackrais-organization/working-date-time-php)\n\n## Overview\nThe **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.\n\n### Features\n- Supports custom **start and end working hours**\n- Skips **weekends and exception dates (holidays)**\n- Supports both **forward and reverse calculations**\n- Allows adding days, hours, minutes within **working time only**\n- Handles **cross-year transitions** while respecting work schedules\n- Efficiently processes **work duration across multiple days**\n- Ideal for **workforce scheduling, deadline calculations, and automated task execution**\n\n## 📌 Table of Contents\n- [Installation](#installation)\n- [How to Use](#how-to-use)\n- [Examples](#examples)\n    - [Default Usage](docs/example_1_default.md)\n    - [Reverse Calculation](docs/example_1_reverse.md)\n- [Algorithm Explanation](#algorithm-explanation)\n- [License](LICENSE.md)\n\n## 🛠 Installation\n\nYou can install this package via Composer:\n```sh\ncomposer require mackrais/working-date-time\n```\n\nAlternatively, you can manually include it in your project.\n\n## 🚀 How to Use\n\n```php\n$workingworking-date-time-php = new Workingworking-date-time-php();\n\n// Forward calculation example\n$calculatedDate = $workingworking-date-time-php\n    -\u003esetExceptionDates(['01-01']) // New Year as an exception date\n    -\u003esetWeekends(['Sunday', 'Saturday']) // Weekends are Saturday and Sunday\n    -\u003esetDateFrom('2024-03-12 10:00:00') // Start date\n    -\u003esetStartHourWorkingDay(8)\n    -\u003esetStartMinuteWorkingDay(0)\n    -\u003esetEndHourWorkingDay(17)\n    -\u003esetEndMinuteWorkingDay(0)\n    -\u003esetDays(2) // Add 2 working days\n    -\u003esetHours(4) // Add 4 working hours\n    -\u003ecalculate()\n    -\u003eformat('Y-m-d H:i:s');\n\n// Output: 2024-03-14 14:00:00\n```\n\n## 🔄 Reverse Calculation Example\n```php\n$workingworking-date-time-php = new Workingworking-date-time-php();\n\n// Reverse calculation example (subtracting time)\n$calculatedDate = $workingworking-date-time-php\n    -\u003esetExceptionDates(['01-01']) // New Year as an exception date\n    -\u003esetWeekends(['Sunday', 'Saturday']) // Weekends\n    -\u003esetDateFrom('2024-03-15 10:00:00') // Start date\n    -\u003esetStartHourWorkingDay(8)\n    -\u003esetStartMinuteWorkingDay(0)\n    -\u003esetEndHourWorkingDay(17)\n    -\u003esetEndMinuteWorkingDay(0)\n    -\u003esetDays(1) // Subtract 1 working day\n    -\u003esetHours(3) // Subtract 3 working hours\n    -\u003esetMinutes(30) // Subtract 30 minutes\n    -\u003easReverse() // Reverse mode\n    -\u003ecalculate()\n    -\u003eformat('Y-m-d H:i:s');\n\n// Output: 2024-03-12 09:30:00\n```\n\n## 📚 Algorithm Explanation\nThe script calculates working time while considering working hours, weekends, and exception dates. The steps are as follows:\n\n### 1️⃣ **Initialize Time Variables**\n- Parse the given `dateFrom` and extract hours, minutes, and seconds.\n- Determine `startOfDay` and `endOfDay` based on working hours.\n\n### 2️⃣ **Apply Additions or Subtractions**\n- If adding time, increment the date by the provided days/hours while skipping weekends and holidays.\n- If subtracting time (reverse mode), decrement accordingly while respecting work hours.\n\n### 3️⃣ **Handle Working Hour Limits**\n- If the added/subtracted time crosses the `endOfDay`, carry over to the next/previous working day.\n- If the computed time lands on a weekend or exception date, shift forward or backward accordingly.\n\n### 4️⃣ **Edge Case Handling**\n- **Cross-Year Transitions**: If the date range includes New Year or other holidays, the script ensures calculations account for them.\n- **Multiple Non-Working Days**: If several holidays or weekends occur consecutively, the script intelligently skips them.\n\n## 🏆 Use Cases\n- **Task Scheduling**: Automate scheduling tasks that should only execute during business hours.\n- **Deadline Calculations**: Compute deadlines that exclude weekends and holidays.\n- **Workforce Management**: Calculate shift times while considering off days and public holidays.\n- **Financial Calculations**: Determine transaction processing dates based on business hours.\n\n## 📜 License\n**working-date-time-php** is released under the MIT License. See the bundled [`LICENSE.md`](LICENSE.md) for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmackrais-organization%2Fworking-date-time-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmackrais-organization%2Fworking-date-time-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmackrais-organization%2Fworking-date-time-php/lists"}