HTML 5 'datetime-local' element has incorrect format

Created on 19 May 2023, over 1 year ago
Updated 15 April 2024, 5 months ago

Problem/Motivation

I have a form that uses the "datetime" element type.
While public static function Datetime::processDatetime, I noticed support for the HTML5 datetime-local element type.

After enabling this option, the default value no longer displayed correctly.

Steps to reproduce

1. Create a form that displays the following element

    $form['field_check_out'] = [
      '#type' => 'datetime',
      '#title' => $this->t('Now'),
      '#default_value' => new DrupalDateTime(),
      // '#date_date_element' => 'datetime-local',
    ];

2. Viewing the form should show the 2 form elements set as current date and time respetively.
3. Uncomment the line that sets '#date_date_element' .
4. Clear cache.
5. The new datetime-local element is not set, but should be.

Proposed resolution

The Datetime::getHtml5DateFormat() returns is incorrect.

- ❌"Y-m-d\TH:i:sO"
- βœ… "Y-m-d\TH:i"

Tested on
- Win10 Chrome 113.0.5672.127 x64
- Win10 Firefox 113.0.1 (x64)

Remaining tasks

- Test on Safari

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
FormΒ  β†’

Last updated less than a minute ago

Created by

πŸ‡―πŸ‡΅Japan tyler36 Osaka

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024