diff --git a/core/config/schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml index 827fe9244f8a39526d6a8c325a8158d7a8c227e0..ad8b9a83db0d93fb592c14ffc03a3f108e865870 100644 --- a/core/config/schema/core.data_types.schema.yml +++ b/core/config/schema/core.data_types.schema.yml @@ -68,7 +68,7 @@ text: # PHP Date format string that is translatable. date_format: type: string - label: 'PHP date format' + label: 'Date format' translatable: true # HTML color value. diff --git a/core/includes/common.inc b/core/includes/common.inc index 349449a2040aa62c3bf3253908c6122e0ebb5f73..252baca0d3015e004042de3a91f5979f84b706a5 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -708,30 +708,6 @@ function _format_date_callback(array $matches = NULL, $new_langcode = NULL) { return $cache[$langcode][$code][$string]; } -/** - * Retrieves the correct datetime format type for this system. - * - * This value is sometimes required when the format type needs to be determined - * before a date can be created. - * - * @return string - * A string as defined in \DrupalComponent\Datetime\DateTimePlus.php: either - * 'intl' or 'php', depending on whether IntlDateFormatter is available. - */ -function datetime_default_format_type() { - static $drupal_static_fast; - if (!isset($drupal_static_fast)) { - $drupal_static_fast['format_type'] = &drupal_static(__FUNCTION__); - } - $format_type = &$drupal_static_fast['format_type']; - - if (!isset($format_type)) { - $date = new DrupalDateTime(); - $format_type = $date->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP; - } - return $format_type; -} - /** * @} End of "defgroup format". */ diff --git a/core/lib/Drupal/Component/Datetime/DateTimePlus.php b/core/lib/Drupal/Component/Datetime/DateTimePlus.php index 44e1f5b1da326db97ef0796d6c629da1d6cee503..4c4122c4c65d074ec5111d6aac2e2ee9a613d228 100644 --- a/core/lib/Drupal/Component/Datetime/DateTimePlus.php +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php @@ -15,16 +15,6 @@ * format, or an array of date parts. It also adds an errors array * and a __toString() method to the date object. * - * In addition, it swaps the IntlDateFormatter into the format() method, - * if it is available. The format() method is also extended with a settings - * array to provide settings needed by the IntlDateFormatter. It will - * will only be used if the class is available, a langcode, country, and - * calendar have been set, and the format is in the right pattern, otherwise - * the parent format() method is used in the usual way. These values can - * either be set globally in the object and reused over and over as the date - * is repeatedly formatted, or set specifically in the format() method - * for the requested format. - * * This class is less lenient than the parent DateTime class. It changes * the default behavior for handling date values like '2011-00-00'. * The parent class would convert that value to '2010-11-30' and report @@ -39,9 +29,6 @@ class DateTimePlus extends \DateTime { const FORMAT = 'Y-m-d H:i:s'; - const CALENDAR = 'gregorian'; - const PHP = 'php'; - const INTL = 'intl'; /** * An array of possible date parts. @@ -90,26 +77,11 @@ class DateTimePlus extends \DateTime { */ protected $langcode = NULL; - /** - * The value of the country code passed to the constructor. - */ - protected $country = NULL; - - /** - * The value of the calendar setting passed to the constructor. - */ - protected $calendar = NULL; - /** * An array of errors encountered when creating this date. */ protected $errors = array(); - /** - * A boolean to store whether or not the intl php extension is available. - */ - static $intlExtentionExists = NULL; - /** * Creates a date object from an input date object. * @@ -205,38 +177,7 @@ public static function createFromFormat($format, $time, $timezone = NULL, $setti // invalid it doesn't return an exception. $datetimeplus = new static('', $timezone, $settings); - $format_string_type = isset($settings['format_string_type']) ? $settings['format_string_type'] : static::PHP; - if ($datetimeplus->canUseIntl() && $format_string_type == static::INTL) { - // Construct the $locale variable needed by the IntlDateFormatter. - $locale = $datetimeplus->langcode . '_' . $datetimeplus->country; - - // If we have information about a calendar, add it. - if (!empty($datetimeplus->calendar) && $datetimeplus->calendar != static::CALENDAR) { - $locale .= '@calendar=' . $datetimeplus->calendar; - } - - // If we're working with a non-gregorian calendar, indicate that. - $calendar_type = \IntlDateFormatter::GREGORIAN; - if ($datetimeplus->calendar != static::CALENDAR) { - $calendar_type = \IntlDateFormatter::TRADITIONAL; - } - - $date_type = !empty($settings['date_type']) ? $settings['date_type'] : \IntlDateFormatter::FULL; - $time_type = !empty($settings['time_type']) ? $settings['time_type'] : \IntlDateFormatter::FULL; - $timezone = !empty($settings['timezone']) ? $settings['timezone'] : $datetimeplus->getTimezone()->getName(); - $formatter = new \IntlDateFormatter($locale, $date_type, $time_type, $timezone, $calendar_type, $format); - - $timestamp = $formatter->parse($time); - if ($timestamp) { - $date = $datetimeplus->createFromTimestamp($timestamp, $timezone, $settings); - } - else { - $date = NULL; - } - } - else { - $date = \DateTime::createFromFormat($format, $time, $datetimeplus->getTimezone()); - } + $date = \DateTime::createFromFormat($format, $time, $datetimeplus->getTimezone()); if (!$date instanceOf \DateTime) { throw new \Exception('The date cannot be created from a format.'); } @@ -271,16 +212,8 @@ public static function createFromFormat($format, $time, $timezone = NULL, $setti * PHP DateTimeZone object, string or NULL allowed. * Defaults to NULL. * @param array $settings - * - langcode: (optional) String two letter language code to construct - * the locale string by the intlDateFormatter class. Used to control - * the result of the format() method if that class is available. - * Defaults to NULL. - * - country: (optional) String two letter country code to construct - * the locale string by the intlDateFormatter class. Used to control - * the result of the format() method if that class is available. - * Defaults to NULL. - * - calendar: (optional) String calendar name to use for the date. - * Defaults to DateTimePlus::CALENDAR. + * - langcode: (optional) String two letter language code used to control + * the result of the format(). Defaults to NULL. * - debug: (optional) Boolean choice to leave debug values in the * date object for debugging purposes. Defaults to FALSE. */ @@ -288,8 +221,6 @@ public function __construct($time = 'now', $timezone = NULL, $settings = array() // Unpack settings. $this->langcode = !empty($settings['langcode']) ? $settings['langcode'] : NULL; - $this->country = !empty($settings['country']) ? $settings['country'] : NULL; - $this->calendar = !empty($settings['calendar']) ? $settings['calendar'] : static::CALENDAR; // Massage the input values as necessary. $prepared_time = $this->prepareTime($time); @@ -571,71 +502,16 @@ public static function datePad($value, $size = 2) { return sprintf("%0" . $size . "d", $value); } - - /** - * Tests whether the IntlDateFormatter can be used. - * - * @param string $calendar - * (optional) String calendar name to use for the date. Defaults to NULL. - * @param string $langcode - * (optional) String two letter language code to construct the locale string - * by the intlDateFormatter class. Defaults to NULL. - * @param string $country - * (optional) String two letter country code to construct the locale string - * by the intlDateFormatter class. Defaults to NULL. - * - * @return bool - * TRUE if IntlDateFormatter can be used. - */ - public function canUseIntl($calendar = NULL, $langcode = NULL, $country = NULL) { - $langcode = !empty($langcode) ? $langcode : $this->langcode; - $country = !empty($country) ? $country : $this->country; - $calendar = !empty($calendar) ? $calendar : $this->calendar; - - return $this->intlDateFormatterExists() && !empty($calendar) && !empty($langcode) && !empty($country); - } - - public static function intlDateFormatterExists() { - if (static::$intlExtentionExists === NULL) { - static::$intlExtentionExists = class_exists('IntlDateFormatter'); - } - return static::$intlExtentionExists; - } - /** * Formats the date for display. * - * Uses the IntlDateFormatter to display the format, if possible. - * Adds an optional array of settings that provides the information - * the IntlDateFormatter will need. - * * @param string $format - * A format string using either PHP's date() or the - * IntlDateFormatter() format. + * A format string using either PHP's date(). * @param array $settings - * - format_string_type: (optional) DateTimePlus::PHP or - * DateTimePlus::INTL. Identifies the pattern used by the format - * string. When using the Intl formatter, the format string must - * use the Intl pattern, which is different from the pattern used - * by the DateTime format function. Defaults to DateTimePlus::PHP. + * - langcode: (optional) String two letter language code used to control + * the result of the format(). Defaults to NULL. * - timezone: (optional) String timezone name. Defaults to the timezone * of the date object. - * - langcode: (optional) String two letter language code to construct the - * locale string by the intlDateFormatter class. Used to control the - * result of the format() method if that class is available. Defaults - * to NULL. - * - country: (optional) String two letter country code to construct the - * locale string by the intlDateFormatter class. Used to control the - * result of the format() method if that class is available. Defaults - * to NULL. - * - calendar: (optional) String calendar name to use for the date, - * Defaults to DateTimePlus::CALENDAR. - * - date_type: (optional) Integer date type to use in the formatter, - * defaults to IntlDateFormatter::FULL. - * - time_type: (optional) Integer date type to use in the formatter, - * defaults to IntlDateFormatter::FULL. - * - lenient: (optional) Boolean choice of whether or not to use lenient - * processing in the intl formatter. Defaults to FALSE; * * @return string * The formatted value of the date. @@ -647,45 +523,9 @@ public function format($format, $settings = array()) { return; } - $format_string_type = isset($settings['format_string_type']) ? $settings['format_string_type'] : static::PHP; - $langcode = !empty($settings['langcode']) ? $settings['langcode'] : $this->langcode; - $country = !empty($settings['country']) ? $settings['country'] : $this->country; - $calendar = !empty($settings['calendar']) ? $settings['calendar'] : $this->calendar; - // Format the date and catch errors. try { - - // If we have what we need to use the IntlDateFormatter, do so. - if ($this->canUseIntl($calendar, $langcode, $country) && $format_string_type == static::INTL) { - - // Construct the $locale variable needed by the IntlDateFormatter. - $locale = $langcode . '_' . $country; - - // If we have information about a calendar, add it. - if (!empty($calendar) && $calendar != static::CALENDAR) { - $locale .= '@calendar=' . $calendar; - } - - // If we're working with a non-gregorian calendar, indicate that. - $calendar_type = \IntlDateFormatter::GREGORIAN; - if ($calendar != self::CALENDAR) { - $calendar_type = \IntlDateFormatter::TRADITIONAL; - } - - $date_type = !empty($settings['date_type']) ? $settings['date_type'] : \IntlDateFormatter::FULL; - $time_type = !empty($settings['time_type']) ? $settings['time_type'] : \IntlDateFormatter::FULL; - $timezone = !empty($settings['timezone']) ? $settings['timezone'] : $this->getTimezone()->getName(); - $formatter = new \IntlDateFormatter($locale, $date_type, $time_type, $timezone, $calendar_type, $format); - - $lenient = !empty($settings['lenient']) ? $settings['lenient'] : FALSE; - $formatter->setLenient($lenient); - $value = $formatter->format($this); - } - - // Otherwise, use the parent method. - else { - $value = parent::format($format); - } + $value = parent::format($format); } catch (\Exception $e) { $this->errors[] = $e->getMessage(); diff --git a/core/lib/Drupal/Core/Datetime/Date.php b/core/lib/Drupal/Core/Datetime/Date.php index 2dd512a58ee8b73de6cd9916714aa8aedd622277..2a31eb7b904c4341b0ef82f11b0f9019988d5646 100644 --- a/core/lib/Drupal/Core/Datetime/Date.php +++ b/core/lib/Drupal/Core/Datetime/Date.php @@ -142,23 +142,19 @@ public function format($timestamp, $type = 'medium', $format = '', $timezone = N ); $date = DrupalDateTime::createFromTimestamp($timestamp, $this->timezones[$timezone], $create_settings); - // Find the appropriate format type. - $key = $date->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP; - // If we have a non-custom date format use the provided date format pattern. if ($date_format = $this->dateFormat($type, $langcode)) { - $format = $date_format->getPattern($key); + $format = $date_format->getPattern(); } // Fall back to medium if a format was not found. if (empty($format)) { - $format = $this->dateFormat('fallback', $langcode)->getPattern($key); + $format = $this->dateFormat('fallback', $langcode)->getPattern(); } // Call $date->format(). $settings = array( 'langcode' => $langcode, - 'format_string_type' => $key, ); return Xss::filter($date->format($format, $settings)); } diff --git a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php index 2d4be4614dafbdfec2e4b81f70b78b5d8942c02b..18b0f9d1ed5ac6add3522ba27293883e3a18eeff 100644 --- a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php +++ b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php @@ -37,29 +37,16 @@ class DrupalDateTime extends DateTimePlus { * possible to a validation step to confirm that the date created * from a format string exactly matches the input. This option * indicates the format can be used for validation. Defaults to TRUE. - * - langcode: (optional) String two letter language code to construct - * the locale string by the intlDateFormatter class. Used to control - * the result of the format() method if that class is available. + * - langcode: (optional) Used to control the result of the format() method. * Defaults to NULL. - * - country: (optional) String two letter country code to construct - * the locale string by the intlDateFormatter class. Used to control - * the result of the format() method if that class is available. - * Defaults to NULL. - * - calendar: (optional) String calendar name to use for the date. - * Defaults to DateTimePlus::CALENDAR. * - debug: (optional) Boolean choice to leave debug values in the * date object for debugging purposes. Defaults to FALSE. */ public function __construct($time = 'now', $timezone = NULL, $settings = array()) { - // We can set the langcode and country using Drupal values. if (!isset($settings['langcode'])) { $settings['langcode'] = \Drupal::languageManager()->getCurrentLanguage()->id; } - if (!isset($settings['country'])) { - $settings['country'] = \Drupal::config('system.date')->get('country.default'); - } - // Instantiate the parent class. parent::__construct($time, $timezone, $settings); @@ -82,75 +69,37 @@ protected function prepareTimezone($timezone) { /** * Overrides format(). * - * Uses the IntlDateFormatter to display the format, if possible. - * Adds an optional array of settings that provides the information - * the IntlDateFormatter will need. - * * @param string $format - * A format string using either PHP's date() or the - * IntlDateFormatter() format. + * A format string using either PHP's date(). * @param array $settings - * - format_string_type: (optional) DateTimePlus::PHP or - * DateTimePlus::INTL. Identifies the pattern used by the format - * string. When using the Intl formatter, the format string must - * use the Intl pattern, which is different from the pattern used - * by the DateTime format function. Defaults to DateTimePlus::PHP. * - timezone: (optional) String timezone name. Defaults to the timezone * of the date object. - * - langcode: (optional) String two letter language code to construct the - * locale string by the intlDateFormatter class. Used to control the - * result of the format() method if that class is available. Defaults - * to NULL. - * - country: (optional) String two letter country code to construct the - * locale string by the intlDateFormatter class. Used to control the - * result of the format() method if that class is available. Defaults - * to NULL. - * - calendar: (optional) String calendar name to use for the date, - * Defaults to DateTimePlus::CALENDAR. - * - date_type: (optional) Integer date type to use in the formatter, - * defaults to IntlDateFormatter::FULL. - * - time_type: (optional) Integer date type to use in the formatter, - * defaults to IntlDateFormatter::FULL. - * - lenient: (optional) Boolean choice of whether or not to use lenient - * processing in the intl formatter. Defaults to FALSE; + * - langcode: (optional) String two letter language code used to control + * the result of the format() method. Defaults to NULL. * * @return string * The formatted value of the date. */ public function format($format, $settings = array()) { - - $settings['format_string_type'] = isset($settings['format_string_type']) ? $settings['format_string_type'] : static::PHP; - $settings['calendar'] = !empty($settings['calendar']) ? $settings['calendar'] : $this->calendar; $settings['langcode'] = !empty($settings['langcode']) ? $settings['langcode'] : $this->langcode; - $settings['country'] = !empty($settings['country']) ? $settings['country'] : $this->country; // Format the date and catch errors. try { - - // If we have what we need to use the IntlDateFormatter, do so. - if ($this->canUseIntl($settings['calendar'], $settings['langcode'], $settings['country']) && $settings['format_string_type'] == parent::INTL) { - $value = parent::format($format, $settings); - } - - // Otherwise, use the default Drupal method. - else { - - // Encode markers that should be translated. 'A' becomes - // '\xEF\AA\xFF'. xEF and xFF are invalid UTF-8 sequences, - // and we assume they are not in the input string. - // Paired backslashes are isolated to prevent errors in - // read-ahead evaluation. The read-ahead expression ensures that - // A matches, but not \A. - $format = preg_replace(array('/\\\\\\\\/', '/(?<!\\\\)([AaeDlMTF])/'), array("\xEF\\\\\\\\\xFF", "\xEF\\\\\$1\$1\xFF"), $format); - - // Call date_format(). - $format = parent::format($format); - - // Pass the langcode to _format_date_callback(). - _format_date_callback(NULL, $settings['langcode']); - - // Translate the marked sequences. - $value = preg_replace_callback('/\xEF([AaeDlMTF]?)(.*?)\xFF/', '_format_date_callback', $format); - } + // Encode markers that should be translated. 'A' becomes + // '\xEF\AA\xFF'. xEF and xFF are invalid UTF-8 sequences, + // and we assume they are not in the input string. + // Paired backslashes are isolated to prevent errors in + // read-ahead evaluation. The read-ahead expression ensures that + // A matches, but not \A. + $format = preg_replace(array('/\\\\\\\\/', '/(?<!\\\\)([AaeDlMTF])/'), array("\xEF\\\\\\\\\xFF", "\xEF\\\\\$1\$1\xFF"), $format); + + // Call date_format(). + $format = parent::format($format); + + // Pass the langcode to _format_date_callback(). + _format_date_callback(NULL, $settings['langcode']); + + // Translate the marked sequences. + $value = preg_replace_callback('/\xEF([AaeDlMTF]?)(.*?)\xFF/', '_format_date_callback', $format); } catch (\Exception $e) { $this->errors[] = $e->getMessage(); diff --git a/core/modules/config_translation/src/FormElement/DateFormat.php b/core/modules/config_translation/src/FormElement/DateFormat.php index 3abb57eca2251c344a2e142929f191d6c44a081c..762968ba09000a194c05eb89d329c77f1b632bb2 100644 --- a/core/modules/config_translation/src/FormElement/DateFormat.php +++ b/core/modules/config_translation/src/FormElement/DateFormat.php @@ -23,12 +23,7 @@ class DateFormat implements ElementInterface { * {@inheritdoc} */ public function getFormElement(array $definition, Language $language, $value) { - if (class_exists('intlDateFormatter')) { - $description = $this->t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array('@url' => 'http://userguide.icu-project.org/formatparse/datetime')); - } - else { - $description = $this->t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array('@url' => 'http://php.net/manual/function.date.php')); - } + $description = $this->t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array('@url' => 'http://php.net/manual/function.date.php')); $format = $this->t('Displayed as %date_format', array('%date_format' => \Drupal::service('date')->format(REQUEST_TIME, 'custom', $value))); return array( '#type' => 'textfield', diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php index 46ef47f1259d8aa1090320d929a341ea2dc57a1c..b01feb8b3cff541f72e52f2f4ac504385a87cde3 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php @@ -403,7 +403,7 @@ public function testDateFormatTranslation() { // Update translatable fields. $edit = array( 'config_names[system.date_format.' . $id . '][label][translation]' => $id . ' - FR', - 'config_names[system.date_format.' . $id . '][pattern][pattern.php][translation]' => 'D', + 'config_names[system.date_format.' . $id . '][pattern][translation]' => 'D', ); // Save language specific version of form. @@ -413,7 +413,7 @@ public function testDateFormatTranslation() { $override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'system.date_format.' . $id); $expected = array( 'label' => $id . ' - FR', - 'pattern' => array('php' => 'D'), + 'pattern' => 'D', ); $this->assertEqual($expected, $override->get()); diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index 3d13b7b7655a0b836305e5d51e07a3e21c59b00a..b9fecdb9b236b9f5ee423422533cde25937e1fca 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -30,17 +30,15 @@ * Implements hook_element_info(). */ function datetime_element_info() { - $format_type = datetime_default_format_type(); - $date_format = ''; $time_format = ''; // Date formats cannot be loaded during install or update. if (!defined('MAINTENANCE_MODE')) { if ($date_format_entity = entity_load('date_format', 'html_date')) { - $date_format = $date_format_entity->getPattern($format_type); + $date_format = $date_format_entity->getPattern(); } if ($time_format_entity = entity_load('date_format', 'html_time')) { - $time_format = $time_format_entity->getPattern($format_type); + $time_format = $time_format_entity->getPattern(); } } $types['datetime'] = array( @@ -51,7 +49,6 @@ function datetime_element_info() { '#theme' => 'datetime_form', '#theme_wrappers' => array('datetime_wrapper'), '#date_date_format' => $date_format, - '#date_format_string_type' => $format_type, '#date_date_element' => 'date', '#date_date_callbacks' => array(), '#date_time_format' => $time_format, @@ -341,7 +338,7 @@ function template_preprocess_datetime_wrapper(&$variables) { * The form element whose value has been processed. */ function datetime_datetime_form_process($element, &$form_state) { - $format_settings = array('format_string_type' => $element['#date_format_string_type']); + $format_settings = array(); // The value callback has populated the #value array. $date = !empty($element['#value']['object']) ? $element['#value']['object'] : NULL; @@ -468,8 +465,7 @@ function form_type_datetime_value($element, $input = FALSE) { try { $date_time_format = trim($date_format . ' ' . $time_format); $date_time_input = trim($date_input . ' ' . $time_input); - $date_time_settings = array('format_string_type' => $element['#date_format_string_type']); - $date = DrupalDateTime::createFromFormat($date_time_format, $date_time_input, $timezone, $date_time_settings); + $date = DrupalDateTime::createFromFormat($date_time_format, $date_time_input, $timezone); } catch (\Exception $e) { $date = NULL; @@ -484,8 +480,8 @@ function form_type_datetime_value($element, $input = FALSE) { $date = $element['#default_value']; if ($date instanceOf DrupalDateTime && !$date->hasErrors()) { $input = array( - 'date' => $date->format($element['#date_date_format'], array('format_string_type' => $element['#date_format_string_type'])), - 'time' => $date->format($element['#date_time_format'], array('format_string_type' => $element['#date_format_string_type'])), + 'date' => $date->format($element['#date_date_format']), + 'time' => $date->format($element['#date_time_format']), 'object' => $date, ); } @@ -564,16 +560,15 @@ function datetime_datetime_validate($element, &$form_state) { * if this is not a HTML5 element. */ function datetime_html5_format($part, $element) { - $format_type = datetime_default_format_type(); switch ($part) { case 'date': switch ($element['#date_date_element']) { case 'date': - return entity_load('date_format', 'html_date')->getPattern($format_type); + return entity_load('date_format', 'html_date')->getPattern(); case 'datetime': case 'datetime-local': - return entity_load('date_format', 'html_datetime')->getPattern($format_type); + return entity_load('date_format', 'html_datetime')->getPattern(); default: return $element['#date_date_format']; @@ -583,7 +578,7 @@ function datetime_html5_format($part, $element) { case 'time': switch ($element['#date_time_element']) { case 'time': - return entity_load('date_format', 'html_time')->getPattern($format_type); + return entity_load('date_format', 'html_time')->getPattern(); default: return $element['#date_time_format']; @@ -604,12 +599,11 @@ function datetime_html5_format($part, $element) { * */ function datetime_format_example($format) { - $format_type = datetime_default_format_type(); $date = &drupal_static(__FUNCTION__); if (empty($date)) { $date = new DrupalDateTime(); } - return $date->format($format, array('format_string_type' => $format_type)); + return $date->format($format); } /** @@ -987,12 +981,10 @@ function datetime_range_years($string, $date = NULL) { * Implements hook_form_BASE_FORM_ID_alter() for node forms. */ function datetime_form_node_form_alter(&$form, &$form_state, $form_id) { - $format_type = datetime_default_format_type(); - // Alter the 'Authored on' date to use datetime. $form['created']['#type'] = 'datetime'; - $date_format = entity_load('date_format', 'html_date')->getPattern($format_type); - $time_format = entity_load('date_format', 'html_time')->getPattern($format_type); + $date_format = entity_load('date_format', 'html_date')->getPattern(); + $time_format = entity_load('date_format', 'html_time')->getPattern(); $form['created']['#description'] = t('Format: %format. Leave blank to use the time of form submission.', array('%format' => datetime_format_example($date_format . ' ' . $time_format))); unset($form['created']['#maxlength']); } diff --git a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDefaultWidget.php b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDefaultWidget.php index ca60f4a1bd2c66b1f2dfe81dbabf2058ea8422ed..161bada4d6de0eca34b49c693ff030df2de03461 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDefaultWidget.php +++ b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDefaultWidget.php @@ -45,8 +45,6 @@ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInter * {@inheritdoc} */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, array &$form_state) { - $format_type = datetime_default_format_type(); - // We are nesting some sub-elements inside the parent, so we need a wrapper. // We also need to add another #title attribute at the top level for ease in // identifying this item in error messages. We do not want to display this @@ -62,7 +60,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen case DateTimeItem::DATETIME_TYPE_DATE: $date_type = 'date'; $time_type = 'none'; - $date_format = $this->dateStorage->load('html_date')->getPattern($format_type); + $date_format = $this->dateStorage->load('html_date')->getPattern(); $time_format = ''; $element_format = $date_format; $storage_format = DATETIME_DATE_STORAGE_FORMAT; @@ -71,8 +69,8 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen default: $date_type = 'date'; $time_type = 'time'; - $date_format = $this->dateStorage->load('html_date')->getPattern($format_type); - $time_format = $this->dateStorage->load('html_time')->getPattern($format_type); + $date_format = $this->dateStorage->load('html_date')->getPattern(); + $time_format = $this->dateStorage->load('html_time')->getPattern(); $element_format = $date_format . ' ' . $time_format; $storage_format = DATETIME_DATETIME_STORAGE_FORMAT; break; diff --git a/core/modules/datetime/src/Tests/DateTimeFieldTest.php b/core/modules/datetime/src/Tests/DateTimeFieldTest.php index a83250c6c1d3f387e454c62f395bd9207cf64be5..0b5caf0d7626c2700f41e95b5e7924046756e92d 100644 --- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/src/Tests/DateTimeFieldTest.php @@ -104,9 +104,8 @@ function testDateField() { // Submit a valid date and ensure it is accepted. $value = '2012-12-31 00:00:00'; $date = new DrupalDateTime($value); - $format_type = $date->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP; - $date_format = entity_load('date_format', 'html_date')->getPattern($format_type); - $time_format = entity_load('date_format', 'html_time')->getPattern($format_type); + $date_format = entity_load('date_format', 'html_date')->getPattern(); + $time_format = entity_load('date_format', 'html_time')->getPattern(); $edit = array( 'user_id' => 1, @@ -174,9 +173,8 @@ function testDatetimeField() { // Submit a valid date and ensure it is accepted. $value = '2012-12-31 00:00:00'; $date = new DrupalDateTime($value); - $format_type = $date->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP; - $date_format = entity_load('date_format', 'html_date')->getPattern($format_type); - $time_format = entity_load('date_format', 'html_time')->getPattern($format_type); + $date_format = entity_load('date_format', 'html_date')->getPattern(); + $time_format = entity_load('date_format', 'html_time')->getPattern(); $edit = array( 'user_id' => 1, diff --git a/core/modules/locale/src/Tests/LocaleConfigTranslationTest.php b/core/modules/locale/src/Tests/LocaleConfigTranslationTest.php index a4ee53a70397bbeda3ce56e4c0ecbe02781ef55e..a638bd501bcf1d58397bbb717b7b6f7f66a7cdca 100644 --- a/core/modules/locale/src/Tests/LocaleConfigTranslationTest.php +++ b/core/modules/locale/src/Tests/LocaleConfigTranslationTest.php @@ -117,7 +117,7 @@ function testConfigTranslation() { // Get translation and check we've only got the site name. $translation = $wrapper->getTranslation($langcode); - $format = $translation->get('pattern')->get('php')->getValue(); + $format = $translation->get('pattern')->getValue(); $this->assertEqual($format, 'D', 'Got the right date format pattern after translation.'); // Formatting the date 8 / 27 / 1985 @ 13:37 EST with pattern D should diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityDateFormat.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityDateFormat.php index 5124ab0960303e35a9d558b9c1ee2376cb4a14a3..695056aa924348fae479a1fb847a849acc541a96 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityDateFormat.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityDateFormat.php @@ -24,7 +24,7 @@ class EntityDateFormat extends EntityConfigBase { */ protected function updateEntityProperty(EntityInterface $entity, array $parents, $value) { if ($parents[0] == 'pattern') { - $entity->setPattern($value, $parents[1]); + $entity->setPattern($value); } else { parent::updateEntityProperty($entity, $parents, $value); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateDateFormatTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateDateFormatTest.php index a79df39a234dec7f2600b08f445a4d4388a29090..c334d940750010b45ae9bf5d6a0fa431b7b3e572 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateDateFormatTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateDateFormatTest.php @@ -44,13 +44,13 @@ public function setUp() { */ public function testDateFormats() { $short_date_format = entity_load('date_format', 'short'); - $this->assertEqual('\S\H\O\R\T m/d/Y - H:i', $short_date_format->getPattern(DrupalDateTime::PHP)); + $this->assertEqual('\S\H\O\R\T m/d/Y - H:i', $short_date_format->getPattern()); $medium_date_format = entity_load('date_format', 'medium'); - $this->assertEqual('\M\E\D\I\U\M D, m/d/Y - H:i', $medium_date_format->getPattern(DrupalDateTime::PHP)); + $this->assertEqual('\M\E\D\I\U\M D, m/d/Y - H:i', $medium_date_format->getPattern()); $long_date_format = entity_load('date_format', 'long'); - $this->assertEqual('\L\O\N\G l, F j, Y - H:i', $long_date_format->getPattern(DrupalDateTime::PHP)); + $this->assertEqual('\L\O\N\G l, F j, Y - H:i', $long_date_format->getPattern()); // Test that we can re-import using the EntityDateFormat destination. Database::getConnection('default', 'migrate') @@ -64,7 +64,7 @@ public function testDateFormats() { $executable->import(); $short_date_format = entity_load('date_format', 'short'); - $this->assertEqual('\S\H\O\R\T d/m/Y - H:i', $short_date_format->getPattern(DrupalDateTime::PHP)); + $this->assertEqual('\S\H\O\R\T d/m/Y - H:i', $short_date_format->getPattern()); } diff --git a/core/modules/system/config/install/system.date_format.fallback.yml b/core/modules/system/config/install/system.date_format.fallback.yml index 86e6927192dfc61537b0d731cc6d0ac6d9d7222e..6e5c9dc22bac41f8bbba0eb9e78e4c518c0ebe75 100644 --- a/core/modules/system/config/install/system.date_format.fallback.yml +++ b/core/modules/system/config/install/system.date_format.fallback.yml @@ -3,6 +3,4 @@ label: 'Fallback date format' status: true langcode: en locked: true -pattern: - php: 'D, m/d/Y - H:i' - intl: 'ccc, MM/dd/yyyy - kk:mm' +pattern: 'D, m/d/Y - H:i' diff --git a/core/modules/system/config/install/system.date_format.html_date.yml b/core/modules/system/config/install/system.date_format.html_date.yml index 5d16688c65e89ef122ffb21b492a6cb53f81fc30..c489b83fa2b1ae171f992eee263ed757a73cf1ec 100644 --- a/core/modules/system/config/install/system.date_format.html_date.yml +++ b/core/modules/system/config/install/system.date_format.html_date.yml @@ -3,6 +3,4 @@ label: 'HTML Date' status: true langcode: en locked: true -pattern: - php: Y-m-d - intl: yyyy-MM-dd +pattern: Y-m-d diff --git a/core/modules/system/config/install/system.date_format.html_datetime.yml b/core/modules/system/config/install/system.date_format.html_datetime.yml index 08bd0a749a0e7c6e366db8a67c10cb7844151b7b..32debaefc67b8c89c4adaad56db1a3197c5295f4 100644 --- a/core/modules/system/config/install/system.date_format.html_datetime.yml +++ b/core/modules/system/config/install/system.date_format.html_datetime.yml @@ -3,6 +3,4 @@ label: 'HTML Datetime' status: true langcode: en locked: true -pattern: - php: 'Y-m-d\TH:i:sO' - intl: 'yyyy-MM-dd''T''kk:mm:ssZZ' +pattern: 'Y-m-d\TH:i:sO' diff --git a/core/modules/system/config/install/system.date_format.html_month.yml b/core/modules/system/config/install/system.date_format.html_month.yml index 95f5bb67596ff64872e1743423cce197d070de19..a3703206e5531559eecd3874b0f40c2e88162a33 100644 --- a/core/modules/system/config/install/system.date_format.html_month.yml +++ b/core/modules/system/config/install/system.date_format.html_month.yml @@ -3,6 +3,4 @@ label: 'HTML Month' status: true langcode: en locked: true -pattern: - php: Y-m - intl: Y-MM +pattern: Y-m diff --git a/core/modules/system/config/install/system.date_format.html_time.yml b/core/modules/system/config/install/system.date_format.html_time.yml index 493dc3907a24ac242e8ed1c3929bab77fc049f98..0c45877c21cee4ded6f4472190e20a779ae09843 100644 --- a/core/modules/system/config/install/system.date_format.html_time.yml +++ b/core/modules/system/config/install/system.date_format.html_time.yml @@ -3,6 +3,4 @@ label: 'HTML Time' status: true langcode: en locked: true -pattern: - php: 'H:i:s' - intl: 'H:mm:ss' +pattern: 'H:i:s' diff --git a/core/modules/system/config/install/system.date_format.html_week.yml b/core/modules/system/config/install/system.date_format.html_week.yml index 0cb16220d0b6684959fcf3ac9732ed82e7bdfd2c..bb5dc6e9cdd943bce504681f8f61e667345ad9b6 100644 --- a/core/modules/system/config/install/system.date_format.html_week.yml +++ b/core/modules/system/config/install/system.date_format.html_week.yml @@ -3,6 +3,4 @@ label: 'HTML Week' status: true langcode: en locked: true -pattern: - php: Y-\WW - intl: 'Y-''W''WW' +pattern: Y-\WW diff --git a/core/modules/system/config/install/system.date_format.html_year.yml b/core/modules/system/config/install/system.date_format.html_year.yml index 23d76721eef26374bc0efe709f4e41dd63af5d7d..1a3aadc0b68e3125b6b534e061a7eb59c39e2df9 100644 --- a/core/modules/system/config/install/system.date_format.html_year.yml +++ b/core/modules/system/config/install/system.date_format.html_year.yml @@ -3,6 +3,4 @@ label: 'HTML Year' status: true langcode: en locked: true -pattern: - php: Y - intl: Y +pattern: Y diff --git a/core/modules/system/config/install/system.date_format.html_yearless_date.yml b/core/modules/system/config/install/system.date_format.html_yearless_date.yml index f88b34d463be39bca727c2cbdc71611e5050b06e..a17ef344d5a72d0b57af19a483bd62d99e23715b 100644 --- a/core/modules/system/config/install/system.date_format.html_yearless_date.yml +++ b/core/modules/system/config/install/system.date_format.html_yearless_date.yml @@ -3,6 +3,4 @@ label: 'HTML Yearless date' status: true langcode: en locked: true -pattern: - php: m-d - intl: MM-d +pattern: m-d diff --git a/core/modules/system/config/install/system.date_format.long.yml b/core/modules/system/config/install/system.date_format.long.yml index 53359deb5f2f725bdcd056b8781451b28f6a8a31..b8a09e31bfd7832864fd0cce11a0a863a3ef45ea 100644 --- a/core/modules/system/config/install/system.date_format.long.yml +++ b/core/modules/system/config/install/system.date_format.long.yml @@ -3,6 +3,4 @@ label: 'Default long date' status: true langcode: en locked: false -pattern: - php: 'l, F j, Y - H:i' - intl: 'EEEE, LLLL d, yyyy - kk:mm' +pattern: 'l, F j, Y - H:i' diff --git a/core/modules/system/config/install/system.date_format.medium.yml b/core/modules/system/config/install/system.date_format.medium.yml index a5f09f8c58961a77bb757fea8cd9ebb575bf913d..59376fdb3d883f6cbe3dcfb0059bf8257c93a717 100644 --- a/core/modules/system/config/install/system.date_format.medium.yml +++ b/core/modules/system/config/install/system.date_format.medium.yml @@ -3,6 +3,4 @@ label: 'Default medium date' status: true langcode: en locked: false -pattern: - php: 'D, m/d/Y - H:i' - intl: 'ccc, MM/dd/yyyy - kk:mm' +pattern: 'D, m/d/Y - H:i' diff --git a/core/modules/system/config/install/system.date_format.short.yml b/core/modules/system/config/install/system.date_format.short.yml index 1452af8f8a0c693800af4fb620d860ba4a787537..654fed40499c27119ff7594b4a562ece7307cfef 100644 --- a/core/modules/system/config/install/system.date_format.short.yml +++ b/core/modules/system/config/install/system.date_format.short.yml @@ -3,6 +3,4 @@ label: 'Default short date' status: true langcode: en locked: false -pattern: - php: 'm/d/Y - H:i' - intl: 'MM/dd/yyyy - kk:mm' +pattern: 'm/d/Y - H:i' diff --git a/core/modules/system/config/schema/system.schema.yml b/core/modules/system/config/schema/system.schema.yml index 690a3ecbd267b3ce05b44b227677e2cd385e5f50..ea18c2d51e099e7df3d6dc1212bfcbe47ce96bd3 100644 --- a/core/modules/system/config/schema/system.schema.yml +++ b/core/modules/system/config/schema/system.schema.yml @@ -134,15 +134,8 @@ system.date_format.*: type: boolean label: 'Locked' pattern: - type: mapping - label: 'Format string' - mapping: - php: - type: date_format - label: 'PHP date format' - intl: - type: string - label: 'Intl date format' + type: date_format + label: 'PHP date format' langcode: type: string label: 'Default language' diff --git a/core/modules/system/src/DateFormatInterface.php b/core/modules/system/src/DateFormatInterface.php index 7a15cb280c038df3c6513a314130ce072998e131..0d6b34b4862a0e388436d256684cf686b99cb9b1 100644 --- a/core/modules/system/src/DateFormatInterface.php +++ b/core/modules/system/src/DateFormatInterface.php @@ -18,26 +18,21 @@ interface DateFormatInterface extends ConfigEntityInterface { /** * Gets the date pattern string for this format. * - * @param string $type - * The date pattern type to set. - * * @return string * The pattern string as expected by date(). */ - public function getPattern($type = DrupalDateTime::PHP); + public function getPattern(); /** * Sets the date pattern for this format. * * @param string $pattern * The date pattern to use for this format. - * @param string $type - * The date pattern type to set. * * @return self * Returns the date format. */ - public function setPattern($pattern, $type = DrupalDateTime::PHP); + public function setPattern($pattern); /** * Determines if this date format is locked. diff --git a/core/modules/system/src/Entity/DateFormat.php b/core/modules/system/src/Entity/DateFormat.php index a3d6ece5f0d45099bbb279237f8114dfb4c7dc67..360c6b55a13302ae84293eca3cfc809d005c8d1f 100644 --- a/core/modules/system/src/Entity/DateFormat.php +++ b/core/modules/system/src/Entity/DateFormat.php @@ -85,15 +85,15 @@ public function toArray() { /** * {@inheritdoc} */ - public function getPattern($type = DrupalDateTime::PHP) { - return isset($this->pattern[$type]) ? $this->pattern[$type] : ''; + public function getPattern() { + return $this->pattern; } /** * {@inheritdoc} */ - public function setPattern($pattern, $type = DrupalDateTime::PHP) { - $this->pattern[$type] = $pattern; + public function setPattern($pattern) { + $this->pattern = $pattern; return $this; } diff --git a/core/modules/system/src/Form/DateFormatEditForm.php b/core/modules/system/src/Form/DateFormatEditForm.php index 3b25d7ed9f02c4c270751f2c10e1773ad938917e..500f5bae70045a3a8f65e6c08d02fe83460a680c 100644 --- a/core/modules/system/src/Form/DateFormatEditForm.php +++ b/core/modules/system/src/Form/DateFormatEditForm.php @@ -20,7 +20,7 @@ public function form(array $form, array &$form_state) { $now = t('Displayed as %date', array('%date' => $this->dateService->format(REQUEST_TIME, $this->entity->id()))); $form['date_format_pattern']['#field_suffix'] = ' <small id="edit-date-format-suffix">' . $now . '</small>'; - $form['date_format_pattern']['#default_value'] = $this->entity->getPattern($this->patternType); + $form['date_format_pattern']['#default_value'] = $this->entity->getPattern(); return $form; } diff --git a/core/modules/system/src/Form/DateFormatFormBase.php b/core/modules/system/src/Form/DateFormatFormBase.php index 3dfb81ef90821bc0215f651f9b2a8b56864341b3..3bfcb60f0febf3cf14876a225d00440b8e360e8c 100644 --- a/core/modules/system/src/Form/DateFormatFormBase.php +++ b/core/modules/system/src/Form/DateFormatFormBase.php @@ -21,13 +21,6 @@ */ abstract class DateFormatFormBase extends EntityForm { - /** - * The date pattern type. - * - * @var string - */ - protected $patternType; - /** * The date service. * @@ -52,7 +45,6 @@ abstract class DateFormatFormBase extends EntityForm { */ public function __construct(Date $date_service, ConfigEntityStorageInterface $date_format_storage) { $date = new DrupalDateTime(); - $this->patternType = $date->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP; $this->dateService = $date_service; $this->dateFormatStorage = $date_format_storage; @@ -136,17 +128,11 @@ public function form(array $form, array &$form_state) { ), ); - if (class_exists('intlDateFormatter')) { - $description = t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array('@url' => 'http://userguide.icu-project.org/formatparse/datetime')); - } - else { - $description = t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array('@url' => 'http://php.net/manual/function.date.php')); - } $form['date_format_pattern'] = array( '#type' => 'textfield', '#title' => t('Format string'), '#maxlength' => 100, - '#description' => $description, + '#description' => $this->t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array('@url' => 'http://php.net/manual/function.date.php')), '#default_value' => '', '#field_suffix' => ' <small id="edit-date-format-suffix"></small>', '#ajax' => array( @@ -190,7 +176,7 @@ public function validate(array $form, array &$form_state) { */ public function submit(array $form, array &$form_state) { $form_state['redirect_route']['route_name'] = 'system.date_format_list'; - $form_state['values']['pattern'][$this->patternType] = trim($form_state['values']['date_format_pattern']); + $form_state['values']['pattern'] = trim($form_state['values']['date_format_pattern']); parent::submit($form, $form_state); $this->entity->save(); diff --git a/core/modules/system/src/Tests/Datetime/DateTimePlusIntlTest.php b/core/modules/system/src/Tests/Datetime/DateTimePlusIntlTest.php deleted file mode 100644 index eb21948c23f0a347db93bcfac02ce59b870f5076..0000000000000000000000000000000000000000 --- a/core/modules/system/src/Tests/Datetime/DateTimePlusIntlTest.php +++ /dev/null @@ -1,90 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\system\Tests\Datetime\DateTimePlusIntlTest. - */ - -namespace Drupal\system\Tests\Datetime; - -use Drupal\Component\Datetime\DateTimePlus; -use Drupal\Core\Datetime\DrupalDateTime; -use Drupal\simpletest\DrupalUnitTestBase; - -/** - * Tests use of PHP's internationalization extension to format dates. - */ -class DateTimePlusIntlTest extends DrupalUnitTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = array('system'); - - public static function getInfo() { - return array( - 'name' => 'DateTimePlusIntl', - 'description' => 'Test DateTimePlus PECL Intl functionality.', - 'group' => 'Datetime', - ); - } - - public function setUp() { - parent::setUp(); - // Install default config for system. - $this->installConfig(array('system')); - } - - /** - * Ensures that PHP's Intl extension is installed. - * - * @return array - * Array of errors containing a list of unmet requirements. - */ - function checkRequirements() { - if (!class_exists('IntlDateFormatter')) { - return array( - 'PHP\'s Intl extension needs to be installed and enabled.', - ); - } - return parent::checkRequirements(); - } - - /** - * Tests that PHP and Intl default formats are equivalent. - */ - function testDateTimestampIntl() { - - // Create date object from a unix timestamp and display it in local time. - $input = '2007-01-31 21:00:00'; - $timezone = 'UTC'; - $intl_settings = array( - 'format_string_type' => DateTimePlus::INTL, - 'country' => 'US', - 'langcode' => 'en', - ); - $php_settings = array( - 'country' => NULL, - 'langcode' => 'en', - ); - - $intl_date = new DateTimePlus($input, $timezone, $intl_settings); - $php_date = new DateTimePlus($input, $timezone, $php_settings); - - $this->assertTrue($intl_date->canUseIntl(), 'DateTimePlus object can use intl when provided with country and langcode settings.'); - $this->assertFalse($php_date->canUseIntl(), 'DateTimePlus object will fallback to use PHP when not provided with country setting.'); - - $default_formats = $this->container->get('entity.manager') - ->getStorage('date_format') - ->loadMultiple(); - - foreach ($default_formats as $format) { - $php_format = $php_date->format($format->getPattern(DrupalDateTime::PHP), $php_settings); - $intl_format = $intl_date->format($format->getPattern(DrupalDateTime::INTL), $intl_settings); - $this->assertIdentical($intl_format, $php_format); - } - } - -} diff --git a/core/modules/system/src/Tests/Datetime/DrupalDateTimeIntlTest.php b/core/modules/system/src/Tests/Datetime/DrupalDateTimeIntlTest.php deleted file mode 100644 index d6dacbd4b9c67ba45e0591d9bacf09ef62aaa8b7..0000000000000000000000000000000000000000 --- a/core/modules/system/src/Tests/Datetime/DrupalDateTimeIntlTest.php +++ /dev/null @@ -1,71 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\system\Tests\Datetime\DrupalDateTimeIntlTest. - */ - -namespace Drupal\system\Tests\Datetime; - -use Drupal\Core\Datetime\DrupalDateTime; -use Drupal\simpletest\DrupalUnitTestBase; - -/** - * Tests use of PHP's internationalization extension to format dates. - */ -class DrupalDateTimeIntlTest extends DrupalUnitTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = array('system'); - - public static function getInfo() { - return array( - 'name' => 'DrupalDateTimeIntl', - 'description' => 'Test DrupalDateTime Intl functionality.', - 'group' => 'Datetime', - ); - } - - public function setUp() { - parent::setUp(); - // Install default config for system. - $this->installConfig(array('system')); - } - - /** - * Ensures that PHP's Intl extension is installed. - * - * @return array - * Array of errors containing a list of unmet requirements. - */ - function checkRequirements() { - if (!class_exists('IntlDateFormatter')) { - return array( - 'PHP\'s Intl extension needs to be installed and enabled.', - ); - } - return parent::checkRequirements(); - } - - /** - * Tests that PHP and Intl default formats are equivalent. - */ - function testDrupalDateTimeIntl() { - $input_value = '2013-09-27 17:40:41'; - $timezone = drupal_get_user_timezone(); - $format = 'yyyy-MM-dd HH:mm:ss'; - $format_settings = array( - 'country' => 'UA', - 'langcode' => 'ru', - 'format_string_type' => DrupalDateTime::INTL - ); - $date = DrupalDateTime::createFromFormat($format, $input_value, $timezone, $format_settings); - $output_value = $date->format($format, $format_settings); - $this->assertIdentical($input_value, $output_value); - } - -} diff --git a/core/modules/system/src/Tests/System/DateTimeTest.php b/core/modules/system/src/Tests/System/DateTimeTest.php index 8f69047d411fc928139457a42a765821ad1b731f..ff9da9479372e5151c46312d9c452df6255919f9 100644 --- a/core/modules/system/src/Tests/System/DateTimeTest.php +++ b/core/modules/system/src/Tests/System/DateTimeTest.php @@ -132,7 +132,7 @@ function testDateFormatXSS() { $date_format = entity_create('date_format', array( 'id' => 'xss_short', 'label' => 'XSS format', - 'pattern' => array('php' => '\<\s\c\r\i\p\t\>\a\l\e\r\t\(\'\X\S\S\'\)\;\<\/\s\c\r\i\p\t\>'), + 'pattern' => '\<\s\c\r\i\p\t\>\a\l\e\r\t\(\'\X\S\S\'\)\;\<\/\s\c\r\i\p\t\>', )); $date_format->save(); diff --git a/core/modules/system/tests/themes/test_basetheme/config/install/system.date_format.fancy.yml b/core/modules/system/tests/themes/test_basetheme/config/install/system.date_format.fancy.yml index 12ae88611714d774538bea9d7bbf211e6d2e4caa..37a0bf83ec5e10a7951e0d7eae5da57df548f2b8 100644 --- a/core/modules/system/tests/themes/test_basetheme/config/install/system.date_format.fancy.yml +++ b/core/modules/system/tests/themes/test_basetheme/config/install/system.date_format.fancy.yml @@ -6,6 +6,4 @@ label: 'Fancy date' status: true langcode: en locked: false -pattern: - php: 'U' - intl: 'EEEE, LLLL d, yyyy - kk:mm' +pattern: 'U'