protected function DateTimeFormatterBase::setTimeZone in Drupal 10
Same name and namespace in other branches
- 8 core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeFormatterBase::setTimeZone()
- 9 core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeFormatterBase::setTimeZone()
Sets the proper time zone on a DrupalDateTime object for the current user.
A DrupalDateTime object loaded from the database will have the UTC time zone applied to it. This method will apply the time zone for the current user, based on system and user settings.
Parameters
\Drupal\Core\Datetime\DrupalDateTime $date: A DrupalDateTime object.
3 calls to DateTimeFormatterBase::setTimeZone()
- DateTimeCustomFormatter::settingsSummary in core/
modules/ datetime/ src/ Plugin/ Field/ FieldFormatter/ DateTimeCustomFormatter.php - Returns a short summary for the current formatter settings.
- DateTimeFormatterBase::buildDate in core/
modules/ datetime/ src/ Plugin/ Field/ FieldFormatter/ DateTimeFormatterBase.php - Creates a render array from a date object.
- DateTimeFormatterBase::buildDateWithIsoAttribute in core/
modules/ datetime/ src/ Plugin/ Field/ FieldFormatter/ DateTimeFormatterBase.php - Creates a render array from a date object with ISO date attribute.
File
- core/
modules/ datetime/ src/ Plugin/ Field/ FieldFormatter/ DateTimeFormatterBase.php, line 165
Class
- DateTimeFormatterBase
- Base class for 'DateTime Field formatter' plugin implementations.
Namespace
Drupal\datetime\Plugin\Field\FieldFormatterCode
protected function setTimeZone(DrupalDateTime $date) {
if ($this
->getFieldSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) {
// A date without time has no timezone conversion.
$timezone = DateTimeItemInterface::STORAGE_TIMEZONE;
}
else {
$timezone = date_default_timezone_get();
}
$date
->setTimeZone(timezone_open($timezone));
}