Core\Time\TimeOfDay::minute
$timeOfDay->minute(): uintReturns the minute of a time of day, as a uint from 0 to 59.
12:15 returns 15, and a time on the hour returns 0. The value is the same number you give to TimeOfDay::at as the second argument.
The result has the same name and type as the minute option of with. So $t->with({ minute: 0 }) gives the start of the same hour. The minute option must be from 0 to 59, and a value outside that range throws a RuntimeError.
Good to know: $t->hour() * 60 + $t->minute() gives the minutes since midnight. Two of these numbers give the minutes between two times on the same day.
Return value
Returns uint. The minute, from 0 to 59.
Changelog
| Version | Change |
|---|---|
0.0.5 | Core\Time\TimeOfDay::hour, Core\Time\TimeOfDay::minute, Core\Time\TimeOfDay::second and Core\Time\TimeOfDay::nanoseconds return the parts of a time as numbers. Each one returns a uint. |
Examples
Read the minute
<?nvs// Shows how to read the minute of a time of day as a number.
Core\Time\TimeOfDay $lunch = Core\Time\TimeOfDay::at(12, 15);
// `minute` returns a `uint` from 0 to 59. This prints 15.echo $lunch->minute(), "\n";
// A time made with `TimeOfDay::at(12, 0)` is on the hour. This prints 0.echo Core\Time\TimeOfDay::at(12, 0)->minute(), "\n";150Minutes since midnight
<?nvs// Shows how to count the minutes between two times on the same day, for a parking ticket.
class Parking{ public static function minutesSinceMidnight(Core\Time\TimeOfDay $time): uint { return $time->hour() * 60 + $time->minute(); }}
Core\Time\TimeOfDay $entered = Core\Time\TimeOfDay::at(9, 40);Core\Time\TimeOfDay $left = Core\Time\TimeOfDay::at(11, 5);
// 09:40 is 580 minutes after midnight, and 11:05 is 665. This prints 85.echo Parking::minutesSinceMidnight($left) - Parking::minutesSinceMidnight($entered), "\n";85The next half hour slot
<?nvs// Shows how to find the next free appointment, when appointments start on the hour and at half past.
class Appointment{ public static function nextSlot(Core\Time\TimeOfDay $now): Core\Time\TimeOfDay { // Before half past, the next slot is at half past this hour. if ($now->minute() < 30) { return $now->with({ minute: 30, second: 0, nanoseconds: 0 }); } // Otherwise it is at the start of the next hour. return $now->with({ minute: 0, second: 0, nanoseconds: 0 })->plus(1, Core\Unit::Hour); }}
// `plus` goes past midnight to 00:00. This prints 10:30, 11:00 and 00:00.echo Appointment::nextSlot(Core\Time\TimeOfDay::at(10, 5))->format('HH:mm'), "\n";echo Appointment::nextSlot(Core\Time\TimeOfDay::at(10, 30))->format('HH:mm'), "\n";echo Appointment::nextSlot(Core\Time\TimeOfDay::at(23, 50))->format('HH:mm'), "\n";10:3011:0000:00