public function TimelineDate::buildArray in Views TimelineJS integration 7.3
Creates an array representing the TimelineJS javascript object.
Return value
array The formatted array.
Overrides TimelineObjectInterface::buildArray
File
- src/
TimelineDate.php, line 41
Class
- TimelineDate
- Converts date strings to TimelineJS3-compatible date arrays.
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 array(
'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->date_string,
);
}