You are here

protected function DateRangeAllDayTrait::buildDateWithIsoAttribute in Date all day 8

1 call to DateRangeAllDayTrait::buildDateWithIsoAttribute()
DateRangeAllDayTrait::viewElements in src/Plugin/Field/FieldFormatter/DateRangeAllDayTrait.php

File

src/Plugin/Field/FieldFormatter/DateRangeAllDayTrait.php, line 78

Class

DateRangeAllDayTrait
A viewElements method, that respects an empty end date.

Namespace

Drupal\date_all_day\Plugin\Field\FieldFormatter

Code

protected function buildDateWithIsoAttribute(DrupalDateTime $date, $all_day = FALSE) {

  // Create the ISO date in Universal Time.
  $iso_date = $date
    ->format("Y-m-d\\TH:i:s") . 'Z';
  $this
    ->setTimeZone($date);
  $build = [
    '#theme' => 'time',
    '#text' => $this
      ->formatDate($date, $all_day),
    '#html' => FALSE,
    '#attributes' => [
      'datetime' => $iso_date,
    ],
    '#cache' => [
      'contexts' => [
        'timezone',
      ],
    ],
  ];
  return $build;
}