bakame / tokei
Immutable value objects for expressive temporal modeling: time, duration, circular 24-hour intervals, and interval sets, without timezone handling.
Fund package maintenance!
Requires
- php: ^8.3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^12.5 || ^13.1.8
- symfony/var-dumper: ^7.4 || ^8.0
Suggests
- ext-intl: to handle time locale string conversion with the best performance
- symfony/polyfill-intl-icu: to handle time locale string conversion via the Symfony polyfill if ext-intl is not present
README
Tokei
Tokei (pronounced: [to̞ke̞ː] or [tokeː]) is a lightweight domain-focused set of immutable value objects for representing and operating on time, durations, including, circular 24-hour intervals, and interval sets, offering expressive temporal modeling without timezone handling.
The framework-agnostic package offers a consistent and expressive way to work with temporal values in a safe and predictable manner.
use Bakame\Tokei\Duration; use Bakame\Tokei\DurationFormat; use Bakame\Tokei\Time; $target = Duration::of(hours: 7, minutes: 33); $alreadyDone = Duration::of(hours: 5, minutes: 17); $remaining = $target->sum($alreadyDone->negated()); $startedNewShiftAt = Time::at(hour: 21, minute: 31); $shouldStopAt = $startedNewShiftAt->shift($remaining); echo "I have to work ", $target->format(DurationFormat::Compact), " today", PHP_EOL; echo "I have already worked for ", $alreadyDone->format(DurationFormat::Compact), PHP_EOL; echo "I still have to work ", $remaining->format(DurationFormat::Compact), PHP_EOL; echo "If I start working again at ", $startedNewShiftAt->format(), PHP_EOL; echo "I will end today's shit at ", $shouldStopAt->format(), PHP_EOL; // Gives the following: /** * I have to work 7h33m today * I have already worked for 5h17m * I still have to work 2h16m * If I start working again at 21:31:00 * I will end today's shit at 23:47:00 */
Installation
composer require bakame/tokei
You need:
- PHP >= 8.4 but the latest stable version of PHP is recommended
- The library does not support 32bit PHP
- to be able to get the locale string version of the time you need the
ext-intlextension or use a polyfill forIntlDateFormatter.
Documentation
Full documentation can be found at https://bakame-php.github.io/tokei
Testing
The library has:
- a PHPUnit test suite.
- a coding style compliance test suite using PHP CS Fixer.
- a code analysis compliance test suite using PHPStan.
To run the tests, run the following command from the project folder.
composer test
Contributing
Contributions are welcome and will be fully credited. Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email nyamsprod@gmail.com instead of using the issue tracker.
Changelog
Please see CHANGELOG for more information on what has changed recently.
