You are here

protected function FixedReferenceDateInterval::getDateInterval in Recurring Time Period 8

Gets a \DateInterval object for the plugin's configuration.

Return value

\DateInterval The date interval object.

2 calls to FixedReferenceDateInterval::getDateInterval()
FixedReferenceDateInterval::calculateEnd in src/Plugin/RecurringPeriod/FixedReferenceDateInterval.php
Calculates the end date and time for the period.
FixedReferenceDateInterval::calculateStart in src/Plugin/RecurringPeriod/FixedReferenceDateInterval.php
Calculates the end of the previous period.

File

src/Plugin/RecurringPeriod/FixedReferenceDateInterval.php, line 131

Class

FixedReferenceDateInterval
Provides a fixed date period.

Namespace

Drupal\recurring_period\Plugin\RecurringPeriod

Code

protected function getDateInterval() {
  $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 $date_interval;
}