Commit 354ff717 authored by catch's avatar catch
Browse files

fix: #3520188 Do not try to load date format when custom date format is provided but not declared

By: tobiasb
By: oily
By: mstrelan
(cherry picked from commit 2d616ade)
parent 31d5ad24
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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();
      }
+1 −1
Original line number Diff line number Diff line
@@ -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',
+11 −0
Original line number Diff line number Diff line
@@ -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.
   *