You are here

protected function SmartDateRecurrenceFormatter::findNextInstance in Smart Date 3.4.x

Same name and namespace in other branches
  1. 8.2 modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php \Drupal\smart_date_recur\Plugin\Field\FieldFormatter\SmartDateRecurrenceFormatter::findNextInstance()
  2. 3.x modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php \Drupal\smart_date_recur\Plugin\Field\FieldFormatter\SmartDateRecurrenceFormatter::findNextInstance()
  3. 3.0.x modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php \Drupal\smart_date_recur\Plugin\Field\FieldFormatter\SmartDateRecurrenceFormatter::findNextInstance()
  4. 3.1.x modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php \Drupal\smart_date_recur\Plugin\Field\FieldFormatter\SmartDateRecurrenceFormatter::findNextInstance()
  5. 3.2.x modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php \Drupal\smart_date_recur\Plugin\Field\FieldFormatter\SmartDateRecurrenceFormatter::findNextInstance()
  6. 3.3.x modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php \Drupal\smart_date_recur\Plugin\Field\FieldFormatter\SmartDateRecurrenceFormatter::findNextInstance()

Helper function to find the next instance from now in a provided range.

1 call to SmartDateRecurrenceFormatter::findNextInstance()
SmartDateRecurrenceFormatter::viewElements in modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php

File

modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php, line 349

Class

SmartDateRecurrenceFormatter
Plugin for a recurrence-optimized formatter for 'smartdate' fields.

Namespace

Drupal\smart_date_recur\Plugin\Field\FieldFormatter

Code

protected function findNextInstance(array $instances) {
  $next_index = -1;
  $time = time();
  $current_upcoming = $this
    ->getSetting('current_upcoming');
  foreach ($instances as $index => $instance) {
    $date_compare = $current_upcoming ? $instance->end_value : $instance->value;
    if ($date_compare > $time) {
      $next_index = $index;
      break;
    }
  }
  return $next_index;
}