There is a lot of thing that will end up confusing with our current date/time handling. We should be sticking to HTML5 input types to not confuse developers about what a drupal input type will give them.

Problem

The example I'll be refereeing to is the node add form.

When datetime module is not enabled we have: <input type="text"> and validation functions, all good.

When datetime is enabled:
array('#type' => 'datetime') will give you <input type="date"><input type="time"> and it will adjust for TZ. So that one is fine as 2 separated fields.
If I follow the doc to have a datetime-local element:
array('#type' => 'datetime-local', '#date_date_element' => 'datetime-local', '#date_time_element' => 'none') will give <input type="datetime-local"> as expected and it'll be adjusted for TZ.

So essentially Drupal datetime behaves like HTML datetime-local input. It still is pretty convoluted to make a HTML5 datetime-local input from Drupal datetime FAPI type.

There is also in system_element_info() this that I'm really not sure belongs:

  $types['date'] = array(
    '#input' => TRUE,
    '#theme' => 'date',
    '#theme_wrappers' => array('form_element'),
  );

Expected

array('#type' => 'date') => <input type="date">
array('#type' => 'time') => <input type="time">
array('#type' => 'datetime') => <input type="datetime"> with TZ information (either Z or an offset like +02:00). If no TZ information the value is not valid.
array('#type' => 'datetime-local') => <input type="datetime-local"> without any TZ information (we suppose datetime TZ is user TZ).

Date + time should only be one field, no need for a date field and a separated time field.

Related

#675348: META: Support HTML5 form input elements
#1496652: Add new HTML5 FAPI Element : datetime-local
#1972660: Add tests for the new HTML5 date elements 'date', 'datetime', 'datetime-local' and 'time'
#1835016: Polyfill date input type

Comments

longwave’s picture

The system_element_info entry is a remnant of D7 (and dates to at least Drupal 4.7), but I don't think it even works properly any more in D8, and should probably be removed. See https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.h... for how it used to work.

tim.plunkett’s picture

Priority: Major » Normal
nod_’s picture

Issue summary: View changes

Got datetime and datetime-local wrong :p

nod_’s picture

Got a bit confused since I read the spec a while ago, updated the summary to be more accurate.

Changes boils down to HTML datetime input must have TZ value with it. HTML datetime-local must not have TZ value.

Since we don't use either of those HTML types there is no "problem" but it still means that the drupal datetime type is essentially a HTML datetime-local input.

nod_’s picture

Issue summary: View changes

reconfused

tim.plunkett’s picture

I was just going to ask "is this truly major", and then I saw that I was the one who promited it...

@nod_, is this truly major? :)

nod_’s picture

If you're trying to use the FAPI date things from code, yes it is.

I have a project with some pretty advanced date stuff in the works. Gave up trying to use D8 when I saw this API, yeah not a lot of willpower but I'm not the only one who'll be in that case.

Compared to the rest of our HTML5 form things, It's the only one that doesn't make sense when you look at it and compare what you should get as form elements.

tim.plunkett’s picture

Priority: Normal » Major
Issue summary: View changes

Then I retract my previous demotion :)

sun’s picture

The Expected chapter makes sense to me.

I only wonder whether we perhaps want to add a #local => TRUE property to #type 'datetime', instead of having two separate #types?

jhedstrom’s picture

Probably too late for 8.0.x since this would require some API changes (unless we could make it BC?).

mpdonadio’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Active » Postponed

I think at this point, with RC1 looming, we need to postpone this to 8.1.x.

catch’s picture

Category: Bug report » Task

Not looking at the priority, but this definitely falls into 'task' category for me - no functional bug.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jhedstrom’s picture

Status: Postponed » Active

Un-postponing, although I'm not sure if this can be achieved without API changes...

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Wonder if still relevant and what's left?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.