{"id":21241674,"url":"https://github.com/smhg/date-timespan-php","last_synced_at":"2025-10-04T00:32:29.553Z","repository":{"id":14821988,"uuid":"17544629","full_name":"smhg/date-timespan-php","owner":"smhg","description":"Timespan classes","archived":false,"fork":false,"pushed_at":"2025-06-01T08:24:16.000Z","size":79,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-11T18:37:51.879Z","etag":null,"topics":["iso8601","php","timespan"],"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/smhg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2014-03-08T15:28:59.000Z","updated_at":"2025-06-01T08:22:07.000Z","dependencies_parsed_at":"2024-06-21T20:19:00.188Z","dependency_job_id":"d5530a70-00dc-48c7-8101-b4fdfeace80c","html_url":"https://github.com/smhg/date-timespan-php","commit_stats":{"total_commits":55,"total_committers":3,"mean_commits":"18.333333333333332","dds":"0.21818181818181814","last_synced_commit":"b608f7d523036c9f5bc5f3644c857b14821097ef"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/smhg/date-timespan-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smhg%2Fdate-timespan-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smhg%2Fdate-timespan-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smhg%2Fdate-timespan-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smhg%2Fdate-timespan-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smhg","download_url":"https://codeload.github.com/smhg/date-timespan-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smhg%2Fdate-timespan-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278249450,"owners_count":25955834,"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","status":"online","status_checked_at":"2025-10-03T02:00:06.070Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["iso8601","php","timespan"],"created_at":"2024-11-21T00:56:37.993Z","updated_at":"2025-10-04T00:32:29.538Z","avatar_url":"https://github.com/smhg.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"date-timespan [![CI](https://github.com/smhg/date-timespan-php/workflows/CI/badge.svg)](https://github.com/smhg/date-timespan-php/actions)\n=============\n\nCollection of PHP classes to work with timespans.\n\nIt differs from [DatePeriod](http://php.net/manual/en/class.dateperiod.php) in that it only defines a timespan/period by a start and end date. It offers _algebraic_ methods to manipulate a timespan or a collection of them. Convert it to a DatePeriod passing a DateInterval to `toPeriod()` when you need to iterate over it.\n\n## Installation\n```bash\n$ composer require smhg/date-timespan\n```\n\n## Methods\n### Timespan\n```php\nuse Timespan\\Timespan;\n\n$start = new DateTime('last monday');\n$end = clone $start;\n$end-\u003emodify('+1 week');\n\n$timespan = new Timespan($start, $end);\n```\n\n#### contains(DateTime)\nReturns whether the timespan contains a date.\n\n#### overlaps(Timespan)\nReturns whether the timespan overlaps with another timespan.\n\n#### diff(Timespan)\nReturns a collection of timespans (pieces of the original timespan) which do not appear in another timespan.\n\n#### merge(Timespan)\nReturns a collection with the merged timespan or both timespans when a merge was not possible.\n\n#### trim(DateTime, DateTime)\nReturns a new timespan fitting within the passed boundaries or `null` if no time remains.\n\n#### compare(Timespan)\nReturns whether the timespan occurs before, together or after another timespan.\n\n#### toPeriod(DateInterval)\nConverts the timespan to a [DatePeriod](http://www.php.net/dateperiod) using an interval.\n\n#### __toString()\nConverts the timespan to a string in [ISO 8601 time interval](https://en.wikipedia.org/wiki/ISO_8601#Time_intervals) format.\n\n#### toArray()\nConverts the timespan to an array with a single `interval` element containing the `toString` representation.\n\n### Collection\n```php\nuse Timespan\\Timespan;\nuse Timespan\\Collection;\n\n$collection = new Collection();\n$collection[] = new Timespan(...);\n```\n#### sort()\nSorts the collection based on the start of each timespan.\n\n#### compress()\nJoins timespans in the collection if they overlap. Also sorts the result.\n\n#### merge()\nMerges the collection with another collection. Also compresses the result.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmhg%2Fdate-timespan-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmhg%2Fdate-timespan-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmhg%2Fdate-timespan-php/lists"}