You are here

protected function TimelineJS::checkStartSlide in Views TimelineJS integration 8.3

Checks a slide date to see if it should be displayed first in the timeline.

Parameters

\DateTime $date: A date from a TimelineJS slide.

1 call to TimelineJS::checkStartSlide()
TimelineJS::buildSlide in src/Plugin/views/style/TimelineJS.php
Builds a timeline slide from the current views data row.

File

src/Plugin/views/style/TimelineJS.php, line 698

Class

TimelineJS
Style plugin to render items as TimelineJS3 slides.

Namespace

Drupal\views_timelinejs\Plugin\views\style

Code

protected function checkStartSlide(DateTime $date) {
  static $smallest_difference;
  if (!isset($smallest_difference)) {
    $smallest_difference = NULL;
  }
  $timestamp = $date
    ->getTimestamp();

  // Return if the date was prior to the UNIX Epoch.
  if ($timestamp === FALSE) {
    return;
  }

  // Calculate the absolute difference between the current time and the date.
  $difference = abs(time() - $timestamp);

  // Update the start slide index if this date is closer to the current time.
  if ($smallest_difference == NULL || $difference < $smallest_difference) {
    $smallest_difference = $difference;
    $this->startSlideIndex = $this->view->row_index;
  }
}