{"id":22056838,"url":"https://github.com/letsjump/workday-helper-php","last_synced_at":"2025-05-12T16:03:26.507Z","repository":{"id":57014171,"uuid":"338535533","full_name":"letsjump/workday-helper-php","owner":"letsjump","description":"Count work days and list holiday events in a range of dates with PHP taking care of public holidays and other custom closing days.","archived":false,"fork":false,"pushed_at":"2022-03-18T09:57:43.000Z","size":52,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-25T04:38:31.676Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/letsjump.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null}},"created_at":"2021-02-13T09:04:39.000Z","updated_at":"2023-10-15T13:49:41.000Z","dependencies_parsed_at":"2022-08-21T14:50:32.024Z","dependency_job_id":null,"html_url":"https://github.com/letsjump/workday-helper-php","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsjump%2Fworkday-helper-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsjump%2Fworkday-helper-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsjump%2Fworkday-helper-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsjump%2Fworkday-helper-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/letsjump","download_url":"https://codeload.github.com/letsjump/workday-helper-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227370664,"owners_count":17770706,"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":[],"created_at":"2024-11-30T16:14:58.281Z","updated_at":"2024-11-30T16:14:58.375Z","avatar_url":"https://github.com/letsjump.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Packagist Downloads](https://img.shields.io/packagist/dt/letsjump/workday-helper-php)](https://packagist.org/packages/letsjump/workday-helper-php/stats)\n[![Packagist License](https://img.shields.io/packagist/l/letsjump/workday-helper-php)](https://github.com/letsjump/workday-helper-php/blob/main/LICENSE)\n[![Packagist Version](https://img.shields.io/packagist/v/letsjump/workday-helper-php)](https://packagist.org/packages/letsjump/workday-helper-php#v1.0.0)\n[![GitHub issues](https://img.shields.io/github/issues/letsjump/workday-helper-php)](https://github.com/letsjump/workday-helper-php/issues)\n[![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/letsjump/workday-helper-php)](https://github.com/letsjump/workday-helper-php/issues)\n[![Scrutinizer code quality (GitHub/Bitbucket)](https://img.shields.io/scrutinizer/quality/g/letsjump/workday-helper-php)](https://scrutinizer-ci.com/g/letsjump/workday-helper-php/)\n\n# WorkdayHelper\nCount workdays and list holiday events in a range of dates with PHP taking care of public holidays and other custom closing days.\n\nInspired by Massimo Simonini getWorkdays() Gist.\n@see     https://gist.github.com/massiws/9593008\n\nBenefits and features:\n- you can specify a range of working days in a week (from Monday to Sunday);\n- you can add custom holidays and business closures, for example as a result of a database query;\n- it returns a calendar of holidays for that specific range of dates;\n- you can use your custom recursive holiday calendar (see `$publicHolidays`);\n- it takes care of the timezone of your application;\n- it automatically calculates Easter, and Easter mondays taking care of the timezone (requires PHP with `ext-calendar`);\n\n## Requirements\n\nPHP 5.6.0 and later\n\n## Composer\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```composer require --prefer-dist letsjump/workday-helper-php```\n\n\nor add\n\n\n```\"letsjump/workday-helper-php\": \"~1.0.0\"```\n\nto the `require` section of your composer.json.\n\n## Manual Installation\n\nIf you do not wish to use Composer, you can download the [latest release](https://github.com/letsjump/workday-helper-php).\n\n```php\nrequire_once('/path/to/workday-helper-php/WorkdayHelper.php');\n```\n\n## Dependencies\n\n### PHP ext-calendar\n\nTo 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.\n\nIf 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.\n\n ## Usage:\n\n1. Count the days worked in January while working from Monday to Friday, taking care of public holidays:\n```php\nuse letsjump\\workdayHelper\\WorkdayHelper;\n\n$closingDays                 = new WorkdayHelper('2021-01-01', '2021-01-31');\n$closingDays-\u003eworkingDays    = [1, 2, 3, 4, 5];\n\necho $closingDays-\u003egetWorkdays(); // (19 days)\n```\n\n2. count the day worked in april while working Monday, Wednesday and Friday, taking care of public holidays:\n\n```php\n$closingDays                 = new WorkdayHelper('2021-04-01', '2021-04-30');\n$closingDays-\u003eworkingDays    = [1, 3, 5];\necho $closingDays-\u003egetWorkdays(); // (12 days)\n```\n\n3. Add a strike to the custom closing days\n\n```php\n$closingDays                 = new WorkdayHelper('2021-01-01', '2021-01-31');\n$closingDays-\u003eworkingDays          = [1, 2, 3, 4, 5];\n$closingDays-\u003ecustomClosing = [\n     [\n         'date'    =\u003e '2021-01-18',\n         'event'   =\u003e 'Strike!',\n         'options' =\u003e [\n             'employee_id'        =\u003e 345,\n             'htmlClass' =\u003e 'deep-purple'\n         ]\n     ],\n];\necho $closingDays-\u003egetWorkdays(); // (18 days)\n```\n\n4. Get the calendar with all the closing days for a specific date interval\n\n```php\n$closingDays                 = new WorkdayHelper('2021-01-01', '2021-12-31');\n$closingDays-\u003eworkingDays          = [0, 1, 2, 3, 4, 5, 6]; // don't forget to set every day of the week!\n\n\u003ctable\u003e\n\u003c?php foreach ($closingDays-\u003egetCalendar() as $holiday): ?\u003e\n\u003ctr\u003e\n     \u003ctd\u003e\u003c?= $holiday['date'] ?\u003e\u003c/td\u003e\n     \u003ctd\u003e\u003c?= $holiday['event'] ?\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c?php endforeach ?\u003e\n\u003c/table\u003e\n```\n\n![Gii module](docs/assets/images/calendar.jpg)\n\n### Add custom closings\n\nCustom closure is an array of events. Each event is an array with this configuration:\n\nkey | value | mandatory\n----|-------|----------\ndate| date in Y-m-d format | yes\nevent | a string representing the name of the closing | yes\noptions | a 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 function | no\n\n__example__\n\n```php\n\n$myInstantatedClass-\u003ecustomClosing = [\n         [\n             'date'  =\u003e '2021-01-10',\n             'event' =\u003e 'Chiusura per ferie'\n         ],\n         [\n             'date'    =\u003e '2021-01-05',\n             'event'   =\u003e 'Strike!',\n             'options' =\u003e [\n                  'id'        =\u003e 345,\n                  'htmlClass' =\u003e 'green'\n             ]\n         ],\n          ...\n];\n```\n\n### Replace the default recursive holiday calendar\n\nThe default recursive holiday calendar is an array of events. Each event is an array with this configuration:\n\nkey | value | mandatory\n----|-------|----------\nm-d | the date must be in m-d format | yes\nevent | a string representing the name of the holiday | yes\noptions | a 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 function | no\n\n__example__\n\n```php\n\n$myInstantatedClass-\u003epublicHolidays = [\n         [\n             'm-d'  =\u003e '12-25',\n             'event' =\u003e 'Christmas'\n         ],\n         [\n             'm-d'    =\u003e '12-26',\n             'event'   =\u003e 'Boxing day',\n             'options' =\u003e [\n                  'id'        =\u003e 345,\n                  'htmlClass' =\u003e 'green'\n             ]\n         ],\n          ...\n];\n```\n\n### Holiday calendar\nThe holiday calendar returns a list of holidays for the working days in the given date range.\nSo 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-\u003eworkingDays[0,1,2,3,4,5,6].\n\nThe output is an array of events. Each array has the unix timestamp of the holiday as key and contains:\n\nkey | value\n----|------\nunixTimestamp | the unix timestamp of the event\ndate | the readable date of the event (you can format it with the parameter `$outputFormat`\nevent | the name of the event type | `public` or `custom` depending if it is a publicHoliday or a customClosing.\noptions | a string or an array of user custom options\n\nExample\n\n```php\n      [\n         [1609455600] =\u003e [\n             [unixTimestamp] =\u003e 1609455600,\n             [date] =\u003e 2021-01-01, # control the format with $outputFormat property\n             [event] =\u003e Capodanno, # description of the event\n             [type] =\u003e public, #public / custom\n             [options] =\u003e # custom option passed by the $customClosing or the $publicHolidays Array\n         ],\n         ...\n      ]\n```\n\n## Side notes\n\nThe 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.\n\nPlease report any bug or whishes into the apposite [issue tracker](https://github.com/letsjump/workday-helper-php/issues)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletsjump%2Fworkday-helper-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fletsjump%2Fworkday-helper-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletsjump%2Fworkday-helper-php/lists"}