public function Interval::add in Commerce Core 8.2
Adds the interval to the given date.
Parameters
\Drupal\Core\Datetime\DrupalDateTime $date: The date.
Return value
\Drupal\Core\Datetime\DrupalDateTime The new date.
1 call to Interval::add()
- Interval::ceil in src/
Interval.php - Increases the date to the upper boundary.
File
- src/
Interval.php, line 95
Class
- Interval
- Provides a value object for intervals (1 month, 14 days, etc).
Namespace
Drupal\commerceCode
public function add(DrupalDateTime $date) : DrupalDateTime {
/** @var \Drupal\Core\Datetime\DrupalDateTime $new_date */
$new_date = clone $date;
$new_date
->modify('+' . $this
->__toString());
// Jan 31st + 1 month should give Feb 28th, not Mar 3rd.
if ($this->unit == 'month' && $new_date
->format('d') !== $date
->format('d')) {
$new_date
->modify('last day of previous month');
}
return $new_date;
}