You are here

protected function DateRangeAllDayDefaultFormatter::formatDate in Date all day 8

Creates a formatted date value as a string.

Parameters

object $date: A date object.

Return value

string A formatted date string using the chosen format.

Overrides DateTimeDefaultFormatter::formatDate

File

src/Plugin/Field/FieldFormatter/DateRangeAllDayDefaultFormatter.php, line 59

Class

DateRangeAllDayDefaultFormatter
Plugin implementation of the 'Default' formatter for 'daterange' fields.

Namespace

Drupal\date_all_day\Plugin\Field\FieldFormatter

Code

protected function formatDate($date, $all_day = FALSE) {
  $format_setting_name = $all_day ? 'date_only_format' : 'format_type';
  $format_type = $this
    ->getSetting($format_setting_name);
  $timezone = $this
    ->getSetting('timezone_override') ?: $date
    ->getTimezone()
    ->getName();
  return $this->dateFormatter
    ->format($date
    ->getTimestamp(), $format_type, '', $timezone != '' ? $timezone : NULL);
}