bakame/tokei

Immutable value objects for expressive temporal modeling: time, duration, circular 24-hour intervals, and interval sets, without timezone handling.

Maintainers

Package info

github.com/bakame-php/tokei

Documentation

pkg:composer/bakame/tokei

Fund package maintenance!

nyamsprod

Statistics

Installs: 10

Dependents: 0

Suggesters: 0

Stars: 7

Open Issues: 0

0.1.0 2026-05-27 11:55 UTC

This package is auto-updated.

Last update: 2026-06-24 08:08:17 UTC


README

tokei

Tokei

Author Software License Build Latest Version Total Downloads Sponsor development of this project

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-intl extension or use a polyfill for IntlDateFormatter.

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.

Credits