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->sub($alreadyDone);
$startedNewShiftAt = Time::at(hour: 21, minute: 31);
$shouldStopAt = $startedNewShiftAt->add($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(DurationFormat::Timer), PHP_EOL;
echo "I will end today's shit at ", $shouldStopAt->format(DurationFormat::Timer), 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
*/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.
Full documentation can be found at https://bakame-php.github.io/tokei
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 testContributions are welcome and will be fully credited. Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email nyamsprod@gmail.com instead of using the issue tracker.
Please see CHANGELOG for more information on what has changed recently.
