1 date.class.inc public BackdropDateTime::merge(BackdropDateTime $other)

Merges two date objects together using the current date values as defaults.

Parameters

BackdropDateTime $other: Another date object to merge with.

Return value

BackdropDateTime: A merged date object.

File

core/includes/date.class.inc, line 157

Class

BackdropDateTime
Extends PHP DateTime class for use with Backdrop.

Code

public function merge(BackdropDateTime $other) {
  $other_tz = $other->getTimezone();
  $this_tz = $this->getTimezone();
  // Figure out which timezone to use for combination.
  $use_tz = ($this->hasGranularity('timezone') || !$other->hasGranularity('timezone')) ? $this_tz : $other_tz;

  $this2 = clone $this;
  $this2->setTimezone($use_tz);
  $other->setTimezone($use_tz);
  $val = $this2->toArray(TRUE);
  $otherval = $other->toArray();
  foreach (self::$allgranularity as $g) {
    if ($other->hasGranularity($g) && !$this2->hasGranularity($g)) {
      // The other class has a property we don't; steal it.
      $this2->addGranularity($g);
      $val[$g] = $otherval[$g];
    }
  }
  $other->setTimezone($other_tz);

  $this2->setDate($val['year'], $val['month'], $val['day']);
  $this2->setTime($val['hour'], $val['minute'], $val['second']);
  return $this2;
}