Core\Time\TimeOfDay
A time on a clock, such as 10:30, with no date and no time zone. TimeOfDay::at makes one, and DateTime::timeOfDay returns the time of a DateTime. plus and minus move it and wrap around at midnight. with changes single fields, and format returns it as text.
A TimeOfDay is a clock reading: hour, minute, second and nanosecond. It has no date and no zone. TimeOfDay::fromIso reads a time written as HH:MM, HH:MM:SS or HH:MM:SS.f, such as 09:30. TimeOfDay::at builds one from numbers, and ->timeOfDay() gives the time of a DateTime. A time written as a string literal in TimeOfDay::fromIso is checked when the program compiles.
plus and minus step by Core\Unit::Hour or a smaller unit, and wrap within the day: 23:30 plus one hour is 00:30. Core\Unit::Day and larger units throw an error, because there is no date to change. format takes the time letters of the patterns DateTime::format uses. A date letter or a zone letter does not compile. DateTime::withTime puts a time onto a date. <, >, <=, >= and compareTo order two times, and == is true for two equal times. toIso() writes the time as text, such as 08:30:00, and TimeOfDay::fromIso reads it back.
hour(), minute(), second() and nanoseconds() return the four fields as numbers. Each returns a uint, with the same name as the field with takes.
<?nvsvar $t = Core\Time\TimeOfDay::fromIso('23:30');echo $t->format('HH:mm:ss'), "\n";echo $t->format('h:mm a'), "\n";
echo $t->plus(1, Core\Unit::Hour)->format('HH:mm'), "\n";echo $t->minus(45, Core\Unit::Minute)->format('HH:mm'), "\n";echo $t->with({ second: 45 })->format('HH:mm:ss'), "\n";echo $t->compareTo(Core\Time\TimeOfDay::at(9, 0)), "\n";
var $d = Core\Time\DateTime::fromIso('2024-03-01 09:00', 'UTC');echo $d->withTime($t)->format('yyyy-MM-dd HH:mm'), "\n";echo $d->timeOfDay()->format('HH:mm'), "\n";23:30:0011:30 PM00:3022:4523:30:4512024-03-01 23:3009:00Returned by
You get a Core\Time\TimeOfDay from these methods:
Members
12 members.
| Member | Signature |
|---|---|
at | at(uint $hour, uint $minute, { second?: uint, nanoseconds?: uint }): Core\Time\TimeOfDay |
fromIso | fromIso(string $text): Core\Time\TimeOfDay |
format | format(string $pattern): string |
plus | plus(int $count, Core\Unit $unit): Core\Time\TimeOfDay |
minus | minus(int $count, Core\Unit $unit): Core\Time\TimeOfDay |
with | with({ hour?: uint, minute?: uint, second?: uint, nanoseconds?: uint }): Core\Time\TimeOfDay |
compareTo | compareTo(Core\Time\TimeOfDay $other): int |
toIso | toIso(): string |
hour | hour(): uint |
minute | minute(): uint |
second | second(): uint |
nanoseconds | nanoseconds(): uint |
