Time\Duration::negate

(PHP 8 >= 8.6.0)

Time\Duration::negate — Returns the duration with the opposite sign

Description

public function Time\Duration::negate(): Time\Duration

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

+add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top