{"id":16954176,"url":"https://github.com/kevinkhill/php-duration","last_synced_at":"2025-04-04T08:05:19.566Z","repository":{"id":28905552,"uuid":"32430400","full_name":"kevinkhill/php-duration","owner":"kevinkhill","description":"Convert durations of time between colon-formatted, human-readable, and seconds","archived":false,"fork":false,"pushed_at":"2023-11-03T08:44:09.000Z","size":53,"stargazers_count":154,"open_issues_count":7,"forks_count":26,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-04T07:46:17.346Z","etag":null,"topics":["duration","hour","minutes","php","seconds"],"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/kevinkhill.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}},"created_at":"2015-03-18T01:20:47.000Z","updated_at":"2024-06-18T12:21:47.634Z","dependencies_parsed_at":"2024-06-18T12:21:42.833Z","dependency_job_id":"b644ab8f-5a44-4231-bef6-86fa760e2581","html_url":"https://github.com/kevinkhill/php-duration","commit_stats":{"total_commits":41,"total_committers":10,"mean_commits":4.1,"dds":0.4878048780487805,"last_synced_commit":"dcb222fd0c9eb459676c9eef6fb9f9d2baf749b1"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinkhill%2Fphp-duration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinkhill%2Fphp-duration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinkhill%2Fphp-duration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinkhill%2Fphp-duration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinkhill","download_url":"https://codeload.github.com/kevinkhill/php-duration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247138174,"owners_count":20890005,"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","hour","minutes","php","seconds"],"created_at":"2024-10-13T22:09:04.112Z","updated_at":"2025-04-04T08:05:19.538Z","avatar_url":"https://github.com/kevinkhill.png","language":"PHP","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=FLP6MYY3PYSFQ"],"categories":[],"sub_categories":[],"readme":"# PHP-Duration\n#### Convert durations between colon formatted time, human-readable time and seconds\n[![Total Downloads](https://img.shields.io/packagist/dt/khill/php-duration.svg?style=plastic)](https://packagist.org/packages/khill/php-duration)\n[![License](https://img.shields.io/packagist/l/khill/php-duration.svg?style=plastic)](http://opensource.org/licenses/MIT)\n[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.3-8892BF.svg?style=plastic)](https://php.net/)\n[![PayPal](https://img.shields.io/badge/paypal-donate-yellow.svg?style=plastic)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=FLP6MYY3PYSFQ)\n\n[![Current Release](https://img.shields.io/github/release/kevinkhill/php-duration.svg?style=plastic)](https://github.com/kevinkhill/php-duration/releases)\n[![Build Status](https://img.shields.io/travis/kevinkhill/php-duration/master.svg?style=plastic)](https://travis-ci.org/kevinkhill/php-duration)\n[![Coverage Status](https://img.shields.io/coveralls/kevinkhill/php-duration/master.svg?style=plastic)](https://coveralls.io/r/kevinkhill/php-duration?branch=master)\n\nThis package was created with a very specific goal in mind, to enable an easy way for users to input how long something took, as a duration of time.\n\nThe library can accept either in colon separated format, like 2:43 for 2 minutes and 43 seconds\nOR\nwritten as human readable or abbreviated time, such as 6m21s for 6 minutes and 21 seconds.\n\nBoth can be converted into seconds and minutes with precision for easy storage into a database.\n\nSeconds, colon separated, abbreviated, all three can be parsed and interchanged.\n - supports hours, minutes, and seconds (with microseconds)\n - humanized input supports any form of the words \"hour\", \"minute\", \"seconds\"\n   - Example, you could input 1h4m2s or 4 Hr. 32 Min.\n\n\n# Install\n```bash\ncomposer require khill/php-duration:~1.0\n```\n\n\n# Usage\n```php\nuse Khill\\Duration\\Duration;\n\n\n$duration = new Duration('7:31');\n\necho $duration-\u003ehumanize();  // 7m 31s\necho $duration-\u003eformatted(); // 7:31\necho $duration-\u003etoSeconds(); // 451\necho $duration-\u003etoMinutes(); // 7.5166\necho $duration-\u003etoMinutes(null, 0); // 8\necho $duration-\u003etoMinutes(null, 2); // 7.52\n```\n\n```php\n$duration = new Duration('1h 2m 5s');\n\necho $duration-\u003ehumanize();  // 1h 2m 5s\necho $duration-\u003eformatted(); // 1:02:05\necho $duration-\u003etoSeconds(); // 3725\necho $duration-\u003etoMinutes(); // 62.0833\necho $duration-\u003etoMinutes(null, 0); // 62\n```\n\n```php\n// Configured for 6 hours per day\n$duration = new Duration('1.5d 1.5h 2m 5s', 6);\n\necho $duration-\u003ehumanize();  // 1d 4h 32m 5s\necho $duration-\u003eformatted(); // 10:32:05\necho $duration-\u003etoSeconds(); // 37925\necho $duration-\u003etoMinutes(); // 632.083333333\necho $duration-\u003etoMinutes(null, 0); // 632\n```\n\n```php\n$duration = new Duration('4293');\n\necho $duration-\u003ehumanize();  // 1h 11m 33s\necho $duration-\u003eformatted(); // 1:11:33\necho $duration-\u003etoSeconds(); // 4293\necho $duration-\u003etoMinutes(); // 71.55\necho $duration-\u003etoMinutes(null, 0); // 72\n```\n\n# Note\nYou do not have to create a new object for each conversion, you can also pass any of the three forms into any of the methods to get the immediate output.\n```php\n$duration = new Duration;\n\necho $duration-\u003ehumanize('1h 2m 5s');  // 1h 2m 5s\necho $duration-\u003eformatted('1h 2m 5s'); // 1:02:05\necho $duration-\u003etoSeconds('1h 2m 5s'); // 3725\necho $duration-\u003etoMinutes('1h 2m 5s'); // 62.0833\necho $duration-\u003etoMinutes('1h 2m 5s', true); // 62\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinkhill%2Fphp-duration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinkhill%2Fphp-duration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinkhill%2Fphp-duration/lists"}