You are here

public function Measurement::add in Physical Fields 8

Adds the given measurement to the current one.

Parameters

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

Return value

static The resulting measurement.

File

src/Measurement.php, line 119

Class

Measurement
Provides a base class for measurement value objects.

Namespace

Drupal\physical

Code

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