magicspacepanda / time-duration
Convert durations into human-readable timestamps.
Installs: 4 797
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.2 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-12-23 02:39:20 UTC
README
This library was created to make parsing time entered into a task manager as easy as it is on popular apps like Harvest or Tempo for JIRA.
Requirements
- PHP 7.2 or higher
- Composer (if used as library)
Install
With Composer
composer require magicspacepanda/time-duration
How to Use
use MagicSpacePanda\TimeDuration; // Handles durations as a float (1 hour and 45 minutes) $floatTime = TimeDuration::createFromNumeric(1.75); printf("Time spend on project is %s", $floatTime); // Handles durations as an integer (3 hours) $intTime = TimeDuration::createFromNumeric(1); printf("Time spend on project is %s", $intTime); // Handles durations as a string (5 hours and 25 minutes) $strTime = TimeDuration::createFromString('5h 25m'); printf("Time spend on project is %s", $strTime); // Convert output to DateTime instance $floatTime->toDateTime(); // Convert output to custom format $intTime->toFormat('H:i'); // Convert output to machine-friendly milliseconds $strTime->toMilliseconds();
Contributing
If you would like to contribute to this library, please create a pull request for me to review. Should your code be accepted I will add your name below.