You are here

public function Measurement::subtract in Physical Fields 8

Subtracts the given measurement from the current one.

Parameters

\Drupal\physical\Measurement $measurement: The measurement.

Return value

static The resulting measurement.

File

src/Measurement.php, line 136

Class

Measurement
Provides a base class for measurement value objects.

Namespace

Drupal\physical

Code

public function subtract(Measurement $measurement) {
  if ($this->unit != $measurement
    ->getUnit()) {
    $measurement = $measurement
      ->convert($this->unit);
  }
  $new_number = Calculator::subtract($this->number, $measurement
    ->getNumber());
  return new static($new_number, $this->unit);
}