You are here

protected function views_timelinejs_plugin_style_timelinejs::check_start_slide in Views TimelineJS integration 7.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 views_timelinejs_plugin_style_timelinejs::check_start_slide()
views_timelinejs_plugin_style_timelinejs::build_slide in ./views_timelinejs_plugin_style_timelinejs.inc
Builds a timeline slide from the current views data row.

File

./views_timelinejs_plugin_style_timelinejs.inc, line 622

Class

views_timelinejs_plugin_style_timelinejs
Style plugin to render items as TimelineJS3 slides.

Code

protected function check_start_slide(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->start_slide_index = $this->view->row_index;
  }
}