Time\Duration::negate
(PHP 8 >= 8.6.0)
Time\Duration::negate — Returns the duration with the opposite sign
Description
Returns a duration of the same length with the opposite sign: a positive duration becomes negative, and a negative duration becomes positive. Negating a duration of zero returns a duration of zero, which is never negative.
Parameters
This function has no parameters.
Return Values
Returns a new Time\Duration object.
Examples
Example #1 Time\Duration::negate() example
<?php
$duration = \Time\Duration::fromSeconds(30);
var_dump($duration->negate()->negative);
var_dump($duration->negate()->negate()->negative);
// A zero duration has no sign.
var_dump(\Time\Duration::fromSeconds(0)->negate()->negative);The above example will output:
bool(true) bool(false) bool(false)
See Also
- Time\Duration::absolute() - Returns the absolute value of the duration
- Time\Duration::sub() - Subtracts a duration
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
