Problem/Motivation

The new and improved <time> element allows 9 different datetime formats.

  • valid month string
  • valid date string
  • valid yearless date string
  • valid time string
  • valid local date and time string
  • valid time-zone offset string
  • valid global date and time string
  • valid week string
  • valid non-negative integer representing a year
  • valid duration string

We don't want people to have to remember HTML's valid date strings and how to format them in PHP.

Proposed resolution

We should offer a helper function that enumerates the options and allows callers to pass in their timestamp and the format as a human-readable string (such as 'week'), along with an optional timezone.

date_iso8601 already is used to create machine readable dates. It could be broadened to output the different acceptable formats.

Remaining tasks

Patch needs to be written.

API changes

date_iso8601 calls would need to be changed to the new function.

CommentFileSizeAuthor
#1 1347648-format_html_datetime.patch11.97 KBlinclark
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

Status: Active » Needs review
FileSize
11.97 KB

The attached patch adds the helper function with tests.

It changes all of the callbacks in RDF mappings from the old function name to the new function name. It also updates the RDF tests to use the DATE_ISO8601 value. Even though the comment in the current function says that it produces invalid RDF, I can't see any reason why it should be invalid. If it is valid ISO8601, it should be valid RDF.

Status: Needs review » Needs work

The last submitted patch, 1347648-format_html_datetime.patch, failed testing.

Anonymous’s picture

Status: Needs work » Needs review

#1: 1347648-format_html_datetime.patch queued for re-testing.

scor’s picture

@linclark yes, the only difference between 'c' and DATE_ISO8601 is the syntax of the timezone (+0000 or +00:00). Both are valid ISO8601. I just checked RDF parsing these and could not find any problem with either.

scor’s picture

Status: Needs review » Needs work
+++ b/core/includes/common.inc
@@ -1915,19 +1915,60 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL
+ *   - datetime: A time on a particular date, i.e. 1978-11-18T06:35:00+00:00.
+++ b/core/includes/common.inc
@@ -1915,19 +1915,60 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL
+ *   i.e. 1978-11-18T05:35:00+01:00.

The function uses Y-m-d\TH:i:sO for the datetime format, which should return a colon-less timezone due to the O date format character. The examples above in the documentation should be updated accordingly.

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

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should 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.

mpdonadio’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Closing this as outdated. We shouldn't be updating the global functions. This can easily live in contrib as wrappers to the date.formatter service.