Time\Duration::negate

Returns the duration with the opposite sign

Description

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

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
  • Time\Duration::sub