You are here

private function SmartDateTrait::addTimeWrapper in Smart Date 3.3.x

Same name and namespace in other branches
  1. 3.2.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::addTimeWrapper()
  2. 3.4.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::addTimeWrapper()

Add spans provides classes to allow the dates and times to be styled.

Parameters

array $instance: The render array of the formatted date range.

object $start_ts: A timestamp.

object $end_ts: A timestamp.

string|null $timezone: An optional timezone override.

4 calls to SmartDateTrait::addTimeWrapper()
SmartDateDailyRangeFormatter::viewElements in modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateDailyRangeFormatter.php
SmartDateDurationFormatter::viewElements in src/Plugin/Field/FieldFormatter/SmartDateDurationFormatter.php
SmartDateRecurrenceFormatter::viewElements in modules/smart_date_recur/src/Plugin/Field/FieldFormatter/SmartDateRecurrenceFormatter.php
SmartDateTrait::viewElements in src/SmartDateTrait.php

File

src/SmartDateTrait.php, line 177

Class

SmartDateTrait
Provides friendly methods for smart date range.

Namespace

Drupal\smart_date

Code

private function addTimeWrapper(array &$instance, $start_ts, $end_ts, $timezone = NULL) {
  $times = [
    'start' => $start_ts,
    'end' => $end_ts,
  ];
  foreach ([
    'start',
    'end',
  ] as $part) {
    if (isset($instance[$part])) {
      if ($this
        ->isAllDay($start_ts, $end_ts, $timezone)) {
        $format = 'Y-m-d';
      }
      else {
        $format = 'c';
      }
      $datetime = \Drupal::service('date.formatter')
        ->format($times[$part], 'custom', $format);
      $current_contents = $instance[$part];
      $instance[$part] = [
        '#theme' => 'time',
        '#attributes' => [
          'datetime' => $datetime,
        ],
        '#text' => $current_contents,
      ];
    }
  }
}