{"id":17164134,"url":"https://github.com/florianv/business","last_synced_at":"2025-05-16T05:06:52.557Z","repository":{"id":32671698,"uuid":"36260149","full_name":"florianv/business","owner":"florianv","description":":date: DateTime calculations in business hours","archived":false,"fork":false,"pushed_at":"2022-06-13T07:53:26.000Z","size":75,"stargazers_count":362,"open_issues_count":4,"forks_count":27,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-13T21:06:14.483Z","etag":null,"topics":["business-hours","date","opening-hours","php"],"latest_commit_sha":null,"homepage":"http://florianv.github.io/business","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/florianv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":"FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"florianv"}},"created_at":"2015-05-25T23:35:02.000Z","updated_at":"2025-02-14T16:54:17.000Z","dependencies_parsed_at":"2022-08-29T04:41:41.897Z","dependency_job_id":null,"html_url":"https://github.com/florianv/business","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/florianv%2Fbusiness","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/florianv%2Fbusiness/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/florianv%2Fbusiness/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/florianv%2Fbusiness/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/florianv","download_url":"https://codeload.github.com/florianv/business/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254471061,"owners_count":22076585,"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-hours","date","opening-hours","php"],"created_at":"2024-10-14T22:51:01.606Z","updated_at":"2025-05-16T05:06:47.542Z","avatar_url":"https://github.com/florianv.png","language":"PHP","funding_links":["https://github.com/sponsors/florianv"],"categories":[],"sub_categories":[],"readme":"# Business [![Build status][travis-image]][travis-url] [![Version][version-image]][version-url] [![PHP Version][php-version-image]][php-version-url]\n\n\u003e DateTime calculations in business hours\n\n## Installation\n\n```bash\n$ composer require florianv/business\n```\n\n## Usage\n\nFirst you need to configure your business schedule:\n\n```php\nuse Business\\SpecialDay;\nuse Business\\Day;\nuse Business\\Days;\nuse Business\\Business;\nuse Business\\Holidays;\nuse Business\\DateRange;\n\n// Opening hours for each week day. If not specified, it is considered closed\n$days = [\n    // Standard days with fixed opening hours\n    new Day(Days::MONDAY, [['09:00', '13:00'], ['2pm', '5 PM']]),\n    new Day(Days::TUESDAY, [['9 AM', '5 PM']]),\n    new Day(Days::WEDNESDAY, [['10:00', '13:00'], ['14:00', '17:00']]),\n    new Day(Days::THURSDAY, [['10 AM', '5 PM']]),\n    \n    // Special day with dynamic opening hours depending on the date\n    new SpecialDay(Days::FRIDAY, function (\\DateTime $date) {\n        if ('2015-05-29' === $date-\u003eformat('Y-m-d')) {\n            return [['9 AM', '12:00']];\n        }\n    \n        return [['9 AM', '5 PM']];\n    }),\n];\n\n// Optional holiday dates\n$holidays = new Holidays([\n    new \\DateTime('2015-01-01'),\n    new \\DateTime('2015-01-02'),\n    new DateRange(new \\DateTime('2015-07-08'), new \\DateTime('2015-07-11')),\n]);\n\n// Optional business timezone\n$timezone = new \\DateTimeZone('Europe/Paris');\n\n// Create a new Business instance\n$business = new Business($days, $holidays, $timezone);\n```\n\n### Methods\n\n##### within() - Tells if a date is within business hours\n\n```php\n$bool = $business-\u003ewithin(new \\DateTime('2015-05-11 10:00'));\n```\n\n##### timeline() - Returns a timeline of business dates\n\n```php\n$start = new \\DateTime('2015-05-11 10:00');\n$end = new \\DateTime('2015-05-14 10:00');\n$interval = new \\DateInterval('P1D');\n\n$dates = $business-\u003etimeline($start, $end, $interval);\n```\n\n##### closest() - Returns the closest business date from a given date\n\n```php\n// After that date (including it)\n$nextDate = $business-\u003eclosest(new \\DateTime('2015-05-11 10:00'));\n\n// Before that date (including it)\n$lastDate = $business-\u003eclosest(new \\DateTime('2015-05-11 10:00'), Business::CLOSEST_LAST);\n```\n\n### Serialization\n\n#### PHP serialization\n\nThe `Business` class can be serialized so it can be stored for later reuse:\n\n```php\n$serialized = serialize($business);\n$business = unserialize($serialized);\n```\n\nIf you use `SpecialDay` instances, you need to install the `jeremeamia/superclosure` library providing closure serialization:\n\n```bash\n$ composer require jeremeamia/superclosure\n```\n\n#### JSON serialization\n\nAll classes can be encoded to JSON\n\n```php\n$json = json_encode($business);\n```\n\nThe `SpecialDay` instances require a context in order extract the data from the callable.\nThis is automatically set to `new \\DateTime('now')` for `json_encode()` call only.\n\n## License\n\n[MIT](https://github.com/florianv/business/blob/master/LICENSE)\n\n[travis-url]: https://travis-ci.org/florianv/business\n[travis-image]: http://img.shields.io/travis/florianv/business.svg?style=flat\n\n[version-url]: https://packagist.org/packages/florianv/business\n[version-image]: http://img.shields.io/packagist/v/florianv/business.svg?style=flat\n\n[php-version-url]: https://packagist.org/packages/florianv/business\n[php-version-image]: http://img.shields.io/badge/php-5.4+-ff69b4.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflorianv%2Fbusiness","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflorianv%2Fbusiness","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflorianv%2Fbusiness/lists"}