You are here

public function Date::buildArray in Views TimelineJS integration 8.3

Creates an array representing the TimelineJS javascript object.

Return value

mixed[] The formatted array.

Overrides ObjectInterface::buildArray

File

src/TimelineJS/Date.php, line 55

Class

Date
Converts date strings to TimelineJS3-compatible date arrays.

Namespace

Drupal\views_timelinejs\TimelineJS

Code

public function buildArray() {

  // The TimelineJS documentation doesn't say anything specific about whether
  // leading zeros should be included in date parts, but the examples do not
  // include them.  Therefore, they are omitted here.
  $exploded_date = explode(',', $this
    ->format('Y,n,j,G,i,s'));

  // Re-key the date array with the property names that TimelineJS expects.
  return [
    'year' => $exploded_date[0],
    'month' => $exploded_date[1],
    'day' => $exploded_date[2],
    'hour' => $exploded_date[3],
    'minute' => $exploded_date[4],
    'second' => $exploded_date[5],
    'display_date' => $this->dateString,
  ];
}