(PHP 8 >= 8.6.0)
Time\Duration::sub — Subtracts a duration
Returns the difference between this duration and
duration.
The signs of both durations are taken into account, so subtracting a
negative duration lengthens a positive one.
If duration is longer than this duration, the
result is negative.
durationThe duration to subtract.
Returns a new Time\Duration object.
If the resulting duration exceeds the maximum length of a duration, a Time\TimeException is thrown.
Example #1 Time\Duration::sub() example
<?php
var_dump(\Time\Duration::fromSeconds(10)->sub(\Time\Duration::fromMilliseconds(2500)));
// Subtracting a larger duration results in a negative duration.
var_dump(\Time\Duration::fromSeconds(1)->sub(\Time\Duration::fromSeconds(3)));Il precedente esempio visualizzerà:
object(Time\Duration)#3 (3) {
["seconds"]=>
int(7)
["nanoseconds"]=>
int(500000000)
["negative"]=>
bool(false)
}
object(Time\Duration)#1 (3) {
["seconds"]=>
int(2)
["nanoseconds"]=>
int(0)
["negative"]=>
bool(true)
}