(PHP 8 >= 8.6.0)
Time\Duration::divideBy — Divides the duration by an integer divisor
Returns a duration that is this duration divided by
divisor.
Any remaining fraction of a nanosecond is truncated, so the result is
rounded towards zero.
The sign of the duration is preserved.
divisor
The divisor.
Must be greater than 0.
Returns a new Time\Duration object.
If divisor is negative, a
ValueError is thrown.
If divisor is 0, a
DivisionByZeroError is thrown.
Example #1 Time\Duration::divideBy() example
<?php
// Fractions of a nanosecond are truncated.
var_dump(\Time\Duration::fromSeconds(10)->divideBy(3)->multiplyBy(3));
try {
\Time\Duration::fromSeconds(10)->divideBy(0);
} catch (DivisionByZeroError $e) {
echo $e->getMessage(), PHP_EOL;
}Il precedente esempio visualizzerà:
object(Time\Duration)#3 (3) {
["seconds"]=>
int(9)
["nanoseconds"]=>
int(999999999)
["negative"]=>
bool(false)
}
Division by zero