Skip to content
Snippets Groups Projects
Commit e2b67d9f authored by aron novak's avatar aron novak
Browse files

Merge branch 'tz-handling' into '1.0.x'

More robust TZ handling

See merge request !19
parents f683604b 2b4753bd
Branches
Tags
No related merge requests found
Pipeline #454110 failed
################
# DrupalCI GitLabCI template
#
# Gitlab-ci.yml to replicate DrupalCI testing for Contrib
#
# With thanks to:
# * The GitLab Acceleration Initiative participants
# * DrupalSpoons
################
################
# Guidelines
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
#
# However, you can modify this template if you have additional needs for your project.
################
################
# Includes
#
# Additional configuration can be provided through includes.
# One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include.
#
# Includes can be overridden by re-declaring anything provided in an include, here in gitlab-ci.yml
# https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values
################
include:
################
# DrupalCI includes:
# As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically.
# View these include files at https://git.drupalcode.org/project/gitlab_templates/
################
- project: $_GITLAB_TEMPLATES_REPO
ref: $_GITLAB_TEMPLATES_REF
file:
- '/includes/include.drupalci.main.yml'
# EXPERIMENTAL: For Drupal 7, remove the above line and uncomment the below.
# - '/includes/include.drupalci.main-d7.yml'
- '/includes/include.drupalci.variables.yml'
- '/includes/include.drupalci.workflows.yml'
################
# Pipeline configuration variables
#
# These are the variables provided to the Run Pipeline form that a user may want to override.
#
# Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/includes/include.drupalci.variables.yml
################
# variables:
# SKIP_ESLINT: '1'
#
# Start custom overrides.
# Based on https://git.drupalcode.org/project/keycdn/-/blob/8.x-1.x/.gitlab-ci.yml
#
variables:
# #Disable default phpunit job in favor of the d9/10 variants below.
# SKIP_PHPUNIT: 1
# SKIP_COMPOSER: 1
# _PHPUNIT_EXTRA: --verbose
# Broaden test coverage.
OPT_IN_TEST_PREVIOUS_MAJOR: 1
OPT_IN_TEST_MAX_PHP: 1
OPT_IN_TEST_NEXT_MINOR: 1
OPT_IN_TEST_NEXT_MAJOR: 1
# Convenient, and we have no secrets.
_SHOW_ENVIRONMENT_VARIABLES: 1
phpcs:
allow_failure: false
phpstan:
allow_failure: false
phpstan (next major):
allow_failure: true
phpstan (next minor):
allow_failure: true
......@@ -90,7 +90,7 @@ class IntlDate {
* @return false|string
* The formatted string or, if an error occurred, <b>FALSE</b>.
*/
public static function format(int $timestamp, string $pattern, string $langcode = NULL, string $timezone = NULL) {
public static function format(int $timestamp, string $pattern, ?string $langcode = NULL, ?string $timezone = NULL) {
if (empty($langcode)) {
$langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
}
......@@ -104,7 +104,8 @@ class IntlDate {
if (isset($map[$langcode])) {
$locale = $map[$langcode];
}
if (empty($timezone)) {
if (empty($timezone) || !in_array($timezone, timezone_identifiers_list())) {
$timezone = NULL;
}
$formatter = new \IntlDateFormatter($locale, \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, $timezone, NULL, $pattern);
......@@ -139,7 +140,7 @@ class IntlDate {
* @return false|string
* The formatted string or, if an error occurred, <b>FALSE</b>.
*/
public static function formatPattern(int $timestamp, string $date_format, string $langcode = NULL, string $timezone = NULL) {
public static function formatPattern(int $timestamp, string $date_format, ?string $langcode = NULL, ?string $timezone = NULL) {
$pattern = \Drupal::entityTypeManager()->getStorage('intl_date_format')->load($date_format);
if (empty($pattern)) {
throw new \IntlException('Invalid intl date format');
......
......@@ -2,6 +2,7 @@
namespace Drupal\intl_date\Plugin\Field\FieldFormatter;
use Drupal\Core\Datetime\TimeZoneFormHelper;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampFormatter;
use Drupal\Core\Form\FormStateInterface;
......@@ -75,7 +76,7 @@ class IntlTimestampFormatter extends TimestampFormatter {
$elements['timezone'] = [
'#type' => 'select',
'#title' => $this->t('Time zone'),
'#options' => ['' => $this->t('- Default site/user time zone -')] + system_time_zones(FALSE, TRUE),
'#options' => ['' => $this->t('- Default site/user time zone -')] + TimeZoneFormHelper::getOptionsListByRegion(),
'#default_value' => $this->getSetting('timezone'),
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment