DatexFormatter.php in Datex 8
File
src/DatexFormatter.php
View source
<?php
namespace Drupal\datex;
use Drupal\Core\Datetime\DateFormatter;
class DatexFormatter extends DateFormatter {
public function format($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
if ($type === 'custom' && $format === 'c' || $format === \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::DATETIME_STORAGE_FORMAT || $format === \Drupal\datetime\Plugin\Field\FieldType\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 = datex_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);
}
}
Classes
Name |
Description |
DatexFormatter |
Extends core's formatter with a locale and translation supporting one. |