(PHP 8 >= 8.6.0)
Time\Duration::add — Adds a duration
Returns the sum of this duration and duration.
The signs of both durations are taken into account, so adding a negative
duration shortens a positive one.
durationThe duration to add.
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::add() example
<?php
$total = \Time\Duration::fromMinutes(1)
->add(\Time\Duration::fromSeconds(30))
->add(\Time\Duration::fromMilliseconds(500));
var_dump($total);
// Adding a negative duration subtracts it.
$result = \Time\Duration::fromSeconds(10)
->add(\Time\Duration::fromSeconds(4)->negate());
var_dump($result->seconds);Il precedente esempio visualizzerà:
object(Time\Duration)#2 (3) {
["seconds"]=>
int(90)
["nanoseconds"]=>
int(500000000)
["negative"]=>
bool(false)
}
int(6)