Loading core/lib/Drupal/Core/Datetime/Element/Datelist.php +4 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ class Datelist extends DateElementBase { * {@inheritdoc} */ public function getInfo() { // Note that since this information is cached, the #date_timezone property // is not set here, as this needs to vary potentially by-user. return [ '#input' => TRUE, '#element_validate' => [ Loading @@ -38,7 +40,6 @@ public function getInfo() { '#date_year_range' => '1900:2050', '#date_increment' => 1, '#date_date_callbacks' => [], '#date_timezone' => date_default_timezone_get(), ]; } Loading @@ -49,6 +50,8 @@ public function getInfo() { * If the date is valid, the date is set in the form. */ public static function valueCallback(&$element, $input, FormStateInterface $form_state) { $element += ['#date_timezone' => date_default_timezone_get()]; $parts = $element['#date_part_order']; $increment = $element['#date_increment']; Loading core/tests/Drupal/KernelTests/Core/Datetime/DatelistElementFormTest.php +17 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,23 @@ public function testDatelistElementUntrustedCallbacks() : void { \Drupal::formBuilder()->getForm($this, 'datelistDateCallback'); } /** * Tests proper timezone handling of the Datelist element. */ public function testTimezoneHandling(): void { // Render the form once with the site's timezone. $form = \Drupal::formBuilder()->getForm($this); $this->render($form); $this->assertEquals('Australia/Sydney', $form['datelist_element']['#date_timezone']); // Mimic a user with a different timezone than Australia/Sydney. date_default_timezone_set('UTC'); $form = \Drupal::formBuilder()->getForm($this); $this->render($form); $this->assertEquals('UTC', $form['datelist_element']['#date_timezone']); } /** * {@inheritdoc} */ Loading Loading
core/lib/Drupal/Core/Datetime/Element/Datelist.php +4 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ class Datelist extends DateElementBase { * {@inheritdoc} */ public function getInfo() { // Note that since this information is cached, the #date_timezone property // is not set here, as this needs to vary potentially by-user. return [ '#input' => TRUE, '#element_validate' => [ Loading @@ -38,7 +40,6 @@ public function getInfo() { '#date_year_range' => '1900:2050', '#date_increment' => 1, '#date_date_callbacks' => [], '#date_timezone' => date_default_timezone_get(), ]; } Loading @@ -49,6 +50,8 @@ public function getInfo() { * If the date is valid, the date is set in the form. */ public static function valueCallback(&$element, $input, FormStateInterface $form_state) { $element += ['#date_timezone' => date_default_timezone_get()]; $parts = $element['#date_part_order']; $increment = $element['#date_increment']; Loading
core/tests/Drupal/KernelTests/Core/Datetime/DatelistElementFormTest.php +17 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,23 @@ public function testDatelistElementUntrustedCallbacks() : void { \Drupal::formBuilder()->getForm($this, 'datelistDateCallback'); } /** * Tests proper timezone handling of the Datelist element. */ public function testTimezoneHandling(): void { // Render the form once with the site's timezone. $form = \Drupal::formBuilder()->getForm($this); $this->render($form); $this->assertEquals('Australia/Sydney', $form['datelist_element']['#date_timezone']); // Mimic a user with a different timezone than Australia/Sydney. date_default_timezone_set('UTC'); $form = \Drupal::formBuilder()->getForm($this); $this->render($form); $this->assertEquals('UTC', $form['datelist_element']['#date_timezone']); } /** * {@inheritdoc} */ Loading