You are here

function CalendarSystemsDrupalDateTime::format in Calendar Systems 8.3

Overrides format().

Parameters

string $format: A format string using either PHP's date().

array $settings:

  • timezone: (optional) String timezone name. Defaults to the timezone of the date object.
  • langcode: (optional) String two letter language code used to control the result of the format() method. Defaults to NULL.

Return value

string The formatted value of the date. Since the format may contain user input, this value should be escaped when output.

Overrides DrupalDateTime::format

File

src/CalendarSystems/CalendarSystemsDrupalDateTime.php, line 36

Class

CalendarSystemsDrupalDateTime

Namespace

Drupal\calendar_systems\CalendarSystems

Code

function format($format, $settings = []) {

  //    $langcode = !empty($settings['langcode']) ? $settings['langcode'] : $this->langcode;
  $value = '';
  try {
    if (!$this
      ->hasErrors()) {
      if (isset($settings['timezone'])) {
        $tz = new DateTimeZone($settings['timezone']);
      }
      else {
        $tz = $this
          ->getTimezone();
      }
      $cal = _calendar_systems_factory($tz, 'en');
      if (!$cal) {
        return parent::format($format, $settings);
      }
      return $cal
        ->setTimestamp($this
        ->getTimestamp())
        ->format($format);
    }
  } catch (Exception $e) {
    $this->errors[] = $e
      ->getMessage();
  }
  return $value;
}