public function Interval::floor in Commerce Core 8.2
Reduces the date to the lower boundary.
For example, an Apr 14th date would be reduced to Apr 1st for monthly intervals, and Jan 1st for yearly intervals.
Parameters
\Drupal\Core\Datetime\DrupalDateTime $date: The date.
Return value
\Drupal\Core\Datetime\DrupalDateTime The new date.
1 call to Interval::floor()
- Interval::ceil in src/
Interval.php - Increases the date to the upper boundary.
File
- src/
Interval.php, line 140
Class
- Interval
- Provides a value object for intervals (1 month, 14 days, etc).
Namespace
Drupal\commerceCode
public function floor(DrupalDateTime $date) : DrupalDateTime {
/** @var \Drupal\Core\Datetime\DrupalDateTime $new_date */
$new_date = clone $date;
switch ($this->unit) {
case 'hour':
$new_date
->setTime($new_date
->format('G'), 0);
break;
case 'day':
$new_date
->setTime(0, 0, 0);
break;
case 'week':
// @todo Account for weeks that start on a sunday.
$new_date
->modify('monday this week');
$new_date
->setTime(0, 0, 0);
break;
case 'month':
$new_date
->modify('first day of this month');
$new_date
->setTime(0, 0, 0);
break;
case 'year':
$new_date
->modify('first day of january');
$new_date
->setTime(0, 0, 0);
break;
}
return $new_date;
}