public function RollingInterval::calculateEnd in Recurring Time Period 8
Calculates the end date and time for the period.
Parameters
\DateTimeImmutable $start: The date and time to begin the period from.
Return value
\DateTimeImmutable|int The expiry date and time, or RecurringPeriodInterface::UNLIMITED.
Overrides RecurringPeriodBase::calculateEnd
1 call to RollingInterval::calculateEnd()
- RollingInterval::calculateDate in src/
Plugin/ RecurringPeriod/ RollingInterval.php - Calculates the end date and time for the period.
File
- src/
Plugin/ RecurringPeriod/ RollingInterval.php, line 76
Class
- RollingInterval
- Provides a period based on a rolling interval from the start date.
Namespace
Drupal\recurring_period\Plugin\RecurringPeriodCode
public function calculateEnd(\DateTimeImmutable $start) {
// Get our interval values from our configuration.
$config = $this
->getConfiguration();
$interval_configuration = $config['interval'];
// The interval plugin ID is the 'period' value.
$interval_plugin_id = $interval_configuration['period'];
// Create a DateInterval that represents the interval.
// TODO: This can be removed when https://www.drupal.org/node/2900435 lands.
$interval_plugin_definition = $this->pluginManagerIntervals
->getDefinition($interval_plugin_id);
$value = $interval_configuration['interval'] * $interval_plugin_definition['multiplier'];
$date_interval = \DateInterval::createFromDateString($value . ' ' . $interval_plugin_definition['php']);
return $start
->add($date_interval);
}