{"id":17705156,"url":"https://github.com/jeromegamez/duration-php","last_synced_at":"2025-09-22T20:30:47.533Z","repository":{"id":46292832,"uuid":"167397035","full_name":"jeromegamez/duration-php","owner":"jeromegamez","description":"Working with durations made easy","archived":false,"fork":false,"pushed_at":"2024-07-13T19:41:19.000Z","size":56,"stargazers_count":39,"open_issues_count":0,"forks_count":9,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-01-07T10:08:51.254Z","etag":null,"topics":["duration","php","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/jeromegamez.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"jeromegamez"}},"created_at":"2019-01-24T16:13:13.000Z","updated_at":"2024-07-13T19:41:23.000Z","dependencies_parsed_at":"2024-10-25T01:12:49.767Z","dependency_job_id":"5ed0e565-22f1-425d-9d76-671e5d7fe3f2","html_url":"https://github.com/jeromegamez/duration-php","commit_stats":{"total_commits":39,"total_committers":3,"mean_commits":13.0,"dds":0.05128205128205132,"last_synced_commit":"7561571792792f2cfcacd51a7bff98b897577b7c"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeromegamez%2Fduration-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeromegamez%2Fduration-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeromegamez%2Fduration-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeromegamez%2Fduration-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeromegamez","download_url":"https://codeload.github.com/jeromegamez/duration-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233883710,"owners_count":18745387,"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":["duration","php","time"],"created_at":"2024-10-24T22:06:47.637Z","updated_at":"2025-09-22T20:30:42.269Z","avatar_url":"https://github.com/jeromegamez.png","language":"PHP","funding_links":["https://github.com/sponsors/jeromegamez"],"categories":[],"sub_categories":[],"readme":"# Duration for PHP\n\nWorking with durations made easy.\n\n[![Current version](https://img.shields.io/packagist/v/gamez/duration.svg)](https://packagist.org/packages/gamez/duration)\n![Supported PHP version](https://img.shields.io/packagist/php-v/gamez/duration.svg)\n[![Code Coverage](https://codecov.io/gh/jeromegamez/duration-php/branch/master/graph/badge.svg)](https://codecov.io/gh/jeromegamez/duration-php)\n[![Sponsor](https://img.shields.io/static/v1?logo=GitHub\u0026label=Sponsor\u0026message=%E2%9D%A4\u0026color=ff69b4)](https://github.com/sponsors/jeromegamez)\n\nDo you like to use `DateInterval` to compute and work with durations? Me neither, so let's fix that!\n\n* [Installation](#installation)\n* [Reference](#reference)\n  * [Supported Input Values](#supported-input-values)\n  * [Transformations](#transformations)\n  * [Comparisons](#comparisons)\n  * [Operations](#operations)\n* [Roadmap](#roadmap)\n\n---\n\n## Installation\n\nYou can install the package with [Composer](https://getcomposer.org):\n\n```bash\ncomposer require gamez/duration\n```\n\nYou can then use Duration:\n\n```php\n\u003c?php\nuse Gamez\\Duration;\n\n$duration = Duration::make('13 minutes 37 seconds');\n// or start with nothing\n$duration = Duration::none();\n```\n\n---\n\n## Reference\n\n### Supported input values\n\n#### DateIntervals\n\n```php\nuse Gamez\\Duration;\n\nDuration::make('PT13M37S');\nDuration::make(new DateInterval('PT13M37S'));\n```\n\n#### Colon notation\n\n```php\nuse Gamez\\Duration;\n\nDuration::make('13:37'); // minutes:seconds\nDuration::make('13:37:37'); // hours:minutes:seconds\n```\n\n#### Textual notation\n\nA textual notation is any value that can be processed by \n[DateInterval::createFromDateString()](https://secure.php.net/manual/en/dateinterval.createfromdatestring.php)\n\n```php\nuse Gamez\\Duration;\n\nDuration::make('13 minutes 37 seconds');\n```\n\n### Transformations\n\nWhen transformed, a Duration will be\n\n* converted to a DateInterval representation\n* optimized in the sense that an input value of 60 seconds would result in an output value of \"1 minute\", \n  for example \"PT60S\" would be converted to \"PT1H\"\n\n```php\nuse Gamez\\Duration;\n\n$duration = Duration::make('8 days 29 hours 77 minutes');\n\necho (string) $duration; // P9DT6H17M\necho json_encode($duration); // \"P9DT6H17M\"\n```\n\n### Comparisons\n\n```php\nuse Gamez\\Duration;\n\n$oneSecond = Duration::make('1 second');\n$sixtySeconds = Duration::make('60 seconds');\n$oneMinute = Duration::make('1 minute');\n$oneHour = Duration::make('1 hour');\n\n$oneSecond-\u003eisSmallerThan($oneMinute); // true\n$oneHour-\u003eisLargerThan($oneMinute); // true\n$oneMinute-\u003eequals($sixtySeconds); // true\n\n$durations = [$oneMinute, $oneSecond, $oneHour, $sixtySeconds];\n\nusort($durations, function ($a, $b) {\n    return $a-\u003ecompareTo($b);\n}); // -\u003e [$oneSecond, $sixtySeconds, $oneMinute, $oneHour]\n```\n\n### Operations\n\nResults will always be rounded by the second.\n\n```php\nuse Gamez\\Duration;\n\n$thirty = Duration::make('30 seconds');\n\necho $thirty-\u003ewithAdded('31 seconds'); // PT1M1S\necho $thirty-\u003ewithSubtracted('29 seconds'); // PT1S\necho $thirty-\u003emultipliedBy(3); // PT1M30S\necho $thirty-\u003edividedBy(2.5); // PT12S\n\n$thirty-\u003emultipliedBy(-1); // InvalidArgumentException\n$thirty-\u003ewithSubtracted('31 seconds'); // InvalidArgumentException\n```\n\n---\n\n## Roadmap\n\n* Support more input formats\n* Add \"output for humans\" (like colon notation)\n* Support precision (similar to [spatie/period](https://github.com/spatie/period))\n* ...\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeromegamez%2Fduration-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeromegamez%2Fduration-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeromegamez%2Fduration-php/lists"}