CalendarSystemsFormatter.php in Calendar Systems 8.3
File
src/CalendarSystemsFormatter.php
View source
<?php
namespace Drupal\calendar_systems;
use Drupal\Core\Datetime\DateFormatter;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
class CalendarSystemsFormatter extends DateFormatter {
public function format($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
if ($type === 'custom' && $format === 'c' || $format === DateTimeItemInterface::DATETIME_STORAGE_FORMAT || $format === DateTimeItemInterface::DATE_STORAGE_FORMAT) {
return parent::format($timestamp, $type, $format, $timezone, $langcode);
}
if (!isset($timezone)) {
$timezone = date_default_timezone_get();
}
if (!isset($this->timezones[$timezone])) {
$this->timezones[$timezone] = timezone_open($timezone);
}
if (empty($langcode)) {
$langcode = $this->languageManager
->getCurrentLanguage()
->getId();
}
$cal = _calendar_systems_factory($this->timezones[$timezone]);
if (!$cal) {
return parent::format($timestamp, $type, $format, $timezone, $langcode);
}
$cal
->setTimestamp($timestamp);
if ($type !== 'custom') {
if ($date_format = $this
->dateFormat($type, $langcode)) {
$format = $date_format
->getPattern();
}
}
if (empty($format)) {
$format = $this
->dateFormat('fallback', $langcode)
->getPattern();
}
return $cal
->format($format);
}
}