{"id":29271288,"url":"https://github.com/kirouane/interval","last_synced_at":"2025-07-04T23:09:39.750Z","repository":{"id":57006992,"uuid":"68734704","full_name":"Kirouane/interval","owner":"Kirouane","description":"This PHP library provides some tools to handle intervals. For instance, you can compute the union or intersection of two intervals. ","archived":false,"fork":false,"pushed_at":"2020-08-06T17:27:22.000Z","size":658,"stargazers_count":28,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-22T04:22:07.018Z","etag":null,"topics":["datetime","exclusions","infinity","intersection","interval","manipulate-intervals","period","php","php7","planning","scheduling","union"],"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/Kirouane.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-20T17:07:33.000Z","updated_at":"2024-07-22T17:34:03.000Z","dependencies_parsed_at":"2022-08-21T12:40:41.141Z","dependency_job_id":null,"html_url":"https://github.com/Kirouane/interval","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/Kirouane/interval","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kirouane%2Finterval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kirouane%2Finterval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kirouane%2Finterval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kirouane%2Finterval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kirouane","download_url":"https://codeload.github.com/Kirouane/interval/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kirouane%2Finterval/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263632056,"owners_count":23491530,"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":["datetime","exclusions","infinity","intersection","interval","manipulate-intervals","period","php","php7","planning","scheduling","union"],"created_at":"2025-07-04T23:09:39.015Z","updated_at":"2025-07-04T23:09:39.732Z","avatar_url":"https://github.com/Kirouane.png","language":"PHP","readme":"[![Travis](https://img.shields.io/travis/Kirouane/interval/master.svg)](http://travis-ci.org/Kirouane/interval)\n[![Coverage Status](https://coveralls.io/repos/github/Kirouane/interval/badge.svg)](https://coveralls.io/github/Kirouane/interval?branch=develop)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/783c18637e574894bc6a37e1c5c75e93)](https://www.codacy.com/app/Kirouane/interval?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=Kirouane/interval\u0026amp;utm_campaign=Badge_Grade)\n[![Total Downloads](https://poser.pugx.org/kirouane/interval/downloads)](https://packagist.org/packages/kirouane/interval)\n[![Latest Stable Version](https://poser.pugx.org/kirouane/interval/v/stable)](https://packagist.org/packages/kirouane/interval)\n\nInterval\n======\n\nThis library provides some tools to handle intervals. For instance, you can compute the union or intersection of two intervals.\n\nUse cases\n------\n* Availabilities calculation.\n* Scheduling/calendar/planning.\n* Mathematics interval computation with open/closed boundaries\n* etc\n\nFeatures\n------\n\n* It computes some operations between two **intervals**: union, intersection and exclusion.\n* It computes some operations between two **sets of intervals**: exclusion for now.\n* It handles several types of boundaries : float, **\\DateTime** and integer. \n* It handles **infinity** type as boundary.\n* Ability to **combine** infinity with \\DateTime and other types.\n* filter, sort, map.\n* Immutability.\n* Chain operations.\n\nQuality\n-------\n\n* Code coverage [![Coverage Status](https://coveralls.io/repos/github/Kirouane/interval/badge.svg)](https://coveralls.io/github/Kirouane/interval?branch=develop)\n* Mutation test : Code coverage more than **90%**\n* Takes care of **performance** and **memory usage**\n* PSR1/PSR2, Code Smell\n\n\nInstall\n------\n\n`composer require kirouane/interval`\n\n\n\nBasic usage\n---------\n\nLet's assume an interval [20, 40].\nWe instantiate a new Interval object .\n\n```php\n$interval = new Interval(20, 40);// [20, 40];\n```\n\nor\n\n```php\n$interval = Interval::create('[20,40]');// [20, 40];\n```\n\n\nWe can do some operations like : \n* Intersection : \n\n```php\necho $interval-\u003eintersect(new Interval(30, 60)); // [30, 40];\n```\n\n* Union : \n\n```php\necho $interval-\u003eunion(new Interval(30, 60)); // {[20, 60]};\n```\n\nor\n\n```php\necho $interval-\u003eunion(new Interval(60, 100)); // {[20, 40], [60, 100]};\n```\n\n* Exclusion : \n\n```php\necho $interval-\u003eexclude(new Interval(30, 60)); // {[20, 30[};\n```\n\nor\n\n```php\necho $interval-\u003eexclude(new Interval(30, 35)); // {[20, 30[, ]35, 40]};\n```\n\nWe can compare two intervals as well: \n* Overlapping test : \n\n```php\necho $interval-\u003eoverlaps(new Interval(30, 60)); // true;\n```\n\n* Inclusion test : \n\n```php\necho $interval-\u003eincludes(new Interval(30, 60)); // false;\n```\nUse DateTimeInterface as boundary\n---------\n\n```php\n$interval = new Interval(new \\DateTime('2016-01-01'), new \\DateTime('2016-01-10'));\n// [2016-01-01T00:00:00+01:00, 2016-01-10T00:00:00+01:00];\n```\n\n* Union : \n\n```php\necho $interval-\u003eunion(Interval::create('[2016-01-10, 2016-01-15]')); \n// {[2016-01-01T00:00:00+01:00, 2016-01-15T00:00:00+01:00]};\n```\n\nUse Infinity as boundary\n---------\n\n```php\n$interval = new Interval(-INF, INF);// ]-∞, +∞[;\n```\n\n* Exclusion : \n\n```php\necho $interval-\u003eexclude(Interval::create('[2016-01-10, 2016-01-15]')); \n// {]-∞, 2016-01-10T00:00:00+01:00[, ]2016-01-15T00:00:00+01:00, +∞[};\n```\n\nOperations on sets (arrays) of intervals\n---------\n\n```php\n$intervals = Intervals::create(['[0,5]', '[8,12]']);// {[0, 5], [8, 12]};\n```\n\n* Exclusion : \n\n```php\necho $intervals-\u003eexclude(Intervals::create(['[3,10]'])); // {[0, 3[, ]10, 12]};\n```\n\nChaining\n---------\n\n```php\n\n$result = Interval\n    ::create('[10, 20]')\n    -\u003eintersect(new Interval(11, 30))\n    -\u003eunion(new Interval(15, INF))\n    -\u003eexclude(Intervals::create(['[18, 20]', '[25, 30]', '[32, 35]', '[12, 13]']))\n    -\u003esort(function (Interval $first, Interval $second) {\n        return $first-\u003egetStart()-\u003egetValue() \u003c=\u003e $second-\u003egetStart()-\u003egetValue();\n    })\n    -\u003emap(function (Interval $interval) {\n        return new Interval(\n            $interval-\u003egetStart()-\u003egetValue() ** 2,\n            $interval-\u003egetEnd()-\u003egetValue() ** 2\n        );\n    })\n    -\u003efilter(function (Interval $interval) {\n        return $interval-\u003egetEnd()-\u003egetValue() \u003e 170;\n    }); \n\n// {[169, 324], [400, 625], [900, 1024], [1225, +∞[};\n    \necho $result;    \n```\n\nAdvanced usage\n---------\n\nYou can create intervals with **open** boundaries : \n\n```php\n\n$result = Intervals\n    ::create([']10, +INF['])\n    -\u003eexclude(Intervals::create([']18, 20]', ']25, 30[', '[32, 35]', ']12, 13]']));\n\n// {]10, 12], ]13, 18], ]20, 25], [30, 32[, ]35, +∞[}\n\n\n```\n\n\n\nContributing\n----------------------\n\nYou are very welcomed to contribute to this Library!\n\n* Clone\n`git clone https://github.com/Kirouane/interval.git`\n\n* Install\n`composer install`\nor\n`make install` (with docker and docker-compose)\n\n* Test\n`vendor/bin/phpunit`   \n\n* Build\n`vendor/bin/grumphp run`\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirouane%2Finterval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkirouane%2Finterval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirouane%2Finterval/lists"}