Loading core/lib/Drupal/Core/Datetime/DateFormatter.php +1 −1 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ public function format($timestamp, $type = 'medium', $format = '', $timezone = N $date = DrupalDateTime::createFromTimestamp($timestamp, $this->timezones[$timezone], $create_settings); // If we have a non-custom date format use the provided date format pattern. if ($type !== 'custom') { if ($type && $type !== 'custom') { if ($date_format = $this->dateFormat($type, $langcode)) { $format = $date_format->getPattern(); } Loading core/lib/Drupal/Core/Datetime/DateFormatterInterface.php +1 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ interface DateFormatterInterface { * * @param int $timestamp * A UNIX timestamp to format. * @param string $type * @param non-empty-string $type * (optional) The format to use, one of: * - One of the built-in formats: 'short', 'medium', * 'long', 'html_datetime', 'html_date', 'html_time', Loading core/tests/Drupal/Tests/Core/Datetime/DateTest.php +11 −0 Original line number Diff line number Diff line Loading @@ -449,6 +449,17 @@ public function testRfc2822DateFormat(): void { } } /** * Tests that the formatter does not call \Drupal\Core\Language\LanguageManagerInterface::getConfigOverrideLanguage. * * The language manager is called by \Drupal\Core\Datetime\DateFormatter::dateFormat, * which should not happen when the type is set to empty string. */ public function testFormatWithEmptyStringAsDateFormatType(): void { $this->languageManager = $this->languageManager->expects($this->never())->method('getConfigOverrideLanguage'); $this->assertSame('00:00:00', $this->dateFormatter->format(0, '', 'H:i:s', 'UTC', 'en')); } /** * Creates a UNIX timestamp given a date and time string. * Loading Loading
core/lib/Drupal/Core/Datetime/DateFormatter.php +1 −1 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ public function format($timestamp, $type = 'medium', $format = '', $timezone = N $date = DrupalDateTime::createFromTimestamp($timestamp, $this->timezones[$timezone], $create_settings); // If we have a non-custom date format use the provided date format pattern. if ($type !== 'custom') { if ($type && $type !== 'custom') { if ($date_format = $this->dateFormat($type, $langcode)) { $format = $date_format->getPattern(); } Loading
core/lib/Drupal/Core/Datetime/DateFormatterInterface.php +1 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ interface DateFormatterInterface { * * @param int $timestamp * A UNIX timestamp to format. * @param string $type * @param non-empty-string $type * (optional) The format to use, one of: * - One of the built-in formats: 'short', 'medium', * 'long', 'html_datetime', 'html_date', 'html_time', Loading
core/tests/Drupal/Tests/Core/Datetime/DateTest.php +11 −0 Original line number Diff line number Diff line Loading @@ -449,6 +449,17 @@ public function testRfc2822DateFormat(): void { } } /** * Tests that the formatter does not call \Drupal\Core\Language\LanguageManagerInterface::getConfigOverrideLanguage. * * The language manager is called by \Drupal\Core\Datetime\DateFormatter::dateFormat, * which should not happen when the type is set to empty string. */ public function testFormatWithEmptyStringAsDateFormatType(): void { $this->languageManager = $this->languageManager->expects($this->never())->method('getConfigOverrideLanguage'); $this->assertSame('00:00:00', $this->dateFormatter->format(0, '', 'H:i:s', 'UTC', 'en')); } /** * Creates a UNIX timestamp given a date and time string. * Loading