Accepted Input Types
Tokei methods accept multiple representations of the same temporal concept.
Values are automatically converted when possible.
Time values
A time can be expressed using any of the following types:
TimeEventDateTimeInterfaceNativeEvent
Example:
use Bakame\Tokei\Interval;
Interval::between(Time::noon(), Time::endOfDay());
Interval::between(new DateTime('2026-05-23 15:23:16'), Time::endOfDay());
Interval::between(Event::at(Time::noon(), 'lunch'), new DateTime('2026-05-23 15:23:16'));
$interval = Interval::between(
Event::at(Time::noon(), 'lunch'),
new DateTime('2026-05-23 15:23:16', new DateTimeZone('Europe/Brussels'))
);
$interval->end->format();
// returns '15:23:16'
Duration values
A duration can be expressed using any of the following types:
DurationDateIntervalIntervalTaskNativeIntervalNativeTask
Example:
Interval::since(
new DateTime('2026-05-23 15:23:16'),
new DateInterval('PT3H')
);
Interval::since(
new DateTime('2026-05-23 15:23:16'),
Duration::of(hours: 3),
);
For Interval types, the interval duration property will be used.
Interval::since(
new DateTime('2026-05-23 15:23:16'),
new DateInterval('P1MT3H')
);
//will throw because the month component is used
Interval values
An interval can be expressed using any of the following types:
IntervalTaskNativeIntervalNativeTask
All remarks related to DateTimeInterface and DateInterval usages are
applicable for interval types.
Identifier values
Identifiers can be expressed using:
Identifiers- classes implementing the
HasIdentifiersinterface stringiterable<Identifiers|HasIdentifiers|string>
Argument rules
| Concept | Accepted representations |
|---|---|
| Time | Time, Event, DateTimeInterface, NativeEvent |
| Duration | Duration, DateInterval, Interval, Task, NativeInterval, NativeTask |
| Interval | Interval, Task, NativeInterval, NativeTask |
| Identifiers | Identifiers, HasIdentifiers, string, iterable |
Unless stated otherwise, any method accepting a temporal primitive also accepts any compatible representation of that primitive.
Time vs Native representations
Tokei distinguishes between two temporal domains:
Time-based types (no date/timezone)
TimeEventIntervalTask
These types represent time-of-day semantics only.
Date and timezone information are not part of their model.
Native types (absolute datetime)
NativeEventNativeIntervalNativeTaskDateTimeInterface
These types represent real-world instants and preserve date and timezone information.
Conversion rule
When a DateTimeInterface is used in a Time-based context, only the time-of-day is used.
When used in a Native context, the full datetime (date + timezone) is preserved.