getSampleDateFormats example

$result = $this->dateFormatter->formatInterval(0, 1, 'xxx-lolspeak');
    $this->assertEquals(new TranslatableMarkup('0 sec', []['langcode' => 'xxx-lolspeak']$this->stringTranslation)$result);
  }

  /** * Tests the getSampleDateFormats method. * * @covers \Drupal\Core\Datetime\DateFormatter::getSampleDateFormats */
  public function testGetSampleDateFormats() {
    $timestamp = strtotime('2015-03-22 14:23:00');
    $expected = $this->dateFormatter->getSampleDateFormats('en', $timestamp, 'Australia/Sydney');

    // Removed characters related to timezone 'e' and 'T', as test does not have     // timezone set.     $date_characters = 'dDjlNSwzWFmMntLoYyaABgGhHisuIOPZcrU';
    $date_chars = str_split($date_characters);

    foreach ($date_chars as $val) {
      $this->assertEquals($expected[$val]date($val$timestamp));
    }
  }

  
$description = $this->t('A user-defined date format. See the <a href="https://www.php.net/manual/datetime.format.php#refsect1-datetime.format-parameters">PHP manual</a> for available options.');
    $format = $this->t('Displayed as %date_format', ['%date_format' => $date_formatter->format(REQUEST_TIME, 'custom', $translation_config)]);

    return [
      '#type' => 'textfield',
      '#description' => $description,
      '#field_suffix' => ' <small data-drupal-date-formatter="preview">' . $format . '</small>',
      '#attributes' => [
        'data-drupal-date-formatter' => 'source',
      ],
      '#attached' => [
        'drupalSettings' => ['dateFormats' => $date_formatter->getSampleDateFormats($translation_language->getId())],
        'library' => ['system/drupal.system.date'],
      ],
    ] + parent::getTranslationElement($translation_language$source_config$translation_config);
  }

}
'data-drupal-date-formatter' => 'source',
      ],
      '#field_suffix' => ' <small class="js-hide" data-drupal-date-formatter="preview">' . $this->t('Displayed as %date_format', ['%date_format' => '']) . '</small>',
    ];

    $form['langcode'] = [
      '#type' => 'language_select',
      '#title' => $this->t('Language'),
      '#languages' => LanguageInterface::STATE_ALL,
      '#default_value' => $this->entity->language()->getId(),
    ];
    $form['#attached']['drupalSettings']['dateFormats'] = $this->dateFormatter->getSampleDateFormats();
    $form['#attached']['library'][] = 'system/drupal.system.date';
    return parent::form($form$form_state);
  }

  /** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form$form_state);

    // The machine name field should already check to see if the requested
Home | Imprint | This part of the site doesn't use cookies.