Datetime Design Pattern - Microformats Wiki (original) (raw)

Use the HTML5 time element for all use-cases that the Datetime Design Pattern was created for, thus use

Historical Archive

The remainder of this page is kept as a historical archive.

The abbr datetime-design-pattern has been dropped.

Purpose

Practical Need

How to use it

For ISO8601 datetimes, use the value-class-pattern instead for better accessibility.

Current uses

The pattern, which is now available as part of hAtom, hCalendar, hCard and hReview, is:

Date Time

where "foo" is the semantic classname which is being applied to this date/time, the title of the is an ISO 8601 date/time, with an appropriate level of specificity, and "Date Time" is a human-friendly representation of the same date/time.

An alternative, if you are using UTC-based timestamps, would be:

Date Time

with a single "Z" as per ISO 8601

Note: title strings of the form "YYYY-MM-DDTHH:MM:SSZ" may be challenging for humans to read and or understand, thus, use the value-class-pattern for datetimes.

Ruby

Ruby: An easy way to get this format from a DateTime is this:

DateTime.now.to_s

Or alternately, if you're working with Time objects:

require 'time' Time.now.iso8601

Profile of ISO8601

Any microformat using the date-time-design pattern SHOULD use a profile of ISO8601. There are currently two widely used profiles which SHOULD be reused.

accessibility issues

Note: Some accessibility-issues have been raised with Datetime Design Pattern, that have been addressed with the completion of the value-class-pattern.

Note also that the accessibility concerns are considerably lessened, even eliminated when using the date-design-pattern, a subset of the datetime-design-pattern.

Discussion

This section need significant gardening, and perhaps archiving of discussions which are primarily historic, as the value-class-pattern serves to solve much of the issues raised here. Tantek


What is the relationship of this pattern to the new


This pattern is likely to be highly resuable.

--User:RyanKing

Can this not be viewed as a microformat in itself?

--User:DimitriGlazkov

It could, but inventing a microformat for the sake of inventing a microformat is against the microformat principles. If there is a specific real world problem (and uses cases) that such an elemental microformat would solve, then it would be worth considering.

Until then it is best to keep the datetime concept merely as a microformat design pattern, to be used in _actual_ microformats that have a demonstrated practical need.

-- Tantek

Excerpt from #microformats Aug 18th. Please edit!

Aug 18 15:16:14 DanC, what do you think of RFC3339? Aug 18 15:17:14 ISO8601 subset Aug 18 15:17:19 Date and Time on the Internet: Timestamps http://www.ietf.org/rfc/rfc3339.txt Aug 18 15:17:30 Klyne is a good guy. I wonder if I talked with him about this. Aug 18 15:17:32 compat with W3C-NOTE-DATETIME Aug 18 15:17:50 compat with xsd:dateTime Aug 18 15:17:57 it's a strict intersection subset Aug 18 15:17:59 I consider W3C-NOTE-DATETIME obsoleted by XML Schema datatype-- yeah.. xsd:dateTime Aug 18 15πŸ”ž32 compare/contrast normatively using xsd:dateTime vs. RFC3339 Aug 18 15πŸ”ž41 note: Atom 1.0 chose RFC3339 Aug 18 15πŸ”ž50 i would like input from the microformats community on this Aug 18 15:19:27 in what context are you evaluating RFC 3339? Aug 18 15:19:28 http://bitworking.org/news/Date_Constructs_in_the_Atom_Syndication_Format Aug 18 15:21:24 which microformat is the question coming from, TantekΒ ? Aug 18 15:23:31 " The grammar element time-second may have the value "60" at the end of Aug 18 15:23:31 months in which a leap second occurs" The XML Schema WG is in the 27th level of leap-second-hell for the past few months, I gather. Aug 18 15:24:21 yeah... here's the scary bit: " Leap seconds cannot be predicted far into the future. The Aug 18 15:24:21 International Earth Rotation Service publishes bulletins [IERS] that Aug 18 15:24:21 announce leap seconds with a few weeks' warning." Aug 18 15:26:03 DanC, which microformats? any/all that use datetime fields. Aug 18 15:26:36 hard to give useful advice, then. Aug 18 15:26:58 I expect they'll use datetime fields for different things that have different cost/benefit trade-offs Aug 18 15:27:26 do you know of any particular differences that matter to anybody? Aug 18 15:56:43 RFC3339 suggests -07:00, which seems like an improvement over -0700 anyway Aug 18 15:56:49 Kragen, agreed Aug 18 15:57:01 RFC3339 is certainly preferable to the ISO8601 subset in iCalendar Aug 18 16:05:57 Tantek's right, Kragen; iCalendar looks like it solves the local timezone problem but doesn't. Aug 18 16:06:14 and it's true that there's no standard solution to the local timezone problem Aug 18 16:06:39 so instead of appearing to solve the problem but not solving it, we chose to provide the ability to approximate the local timezone using e.g. "-07:00" Aug 18 16:06:49 the simplest thing is to have people use Z time in hCalendar. But I gather that's unacceptably unusable? Aug 18 16:07:35 DanC, yes, the simplest thing is to have everyone use UTC Z Aug 18 16:07:38 However Aug 18 16:07:50 it is not nearly as usuable/verifiable Aug 18 16:07:55 as -07:00 etc. Aug 18 16:08:02 hence the decision to go with the latter Aug 18 16:08:12 some degree of human verifiability is important here Aug 18 16:14:21 DanC, my perception is that RFC3339 is a subset Aug 18 16:17:00 time-numoffset = ("+" / "-") time-hour ":" time-minute Aug 18 16:17:34 ok, then I can't see any differences. (modulo recent leap seconds issues that may affect xsd:dateTime ) Aug 18 16πŸ”ž07 would be interesting to know why Atom 1.0 chose RFC3339 over xsd:dateTime Aug 18 16πŸ”ž21 if there was a "real" reason or if it was arbitrary / coin-flip.

Here's an exhaustive comparison from ndw. I think xsd:dateTime also allows unqualified local times, while RFC3339 allows only UTC with no known timezone (-00:00). In the end, Atompub followed the advice of Sam Ruby and Scott Hollenbeck, our area director. Atom dates make some additional restrictions on RFC3339, such as uppercase T and Z characters for compatibility with xsd:dateTime, RFC3339, W3C-DTF, and ISO8601. --Robert Sayre

Aug 18 16πŸ”ž43 rfc3339 is pretty short. Aug 18 16:19:36 DanC, BTW, which came first? REC for xsd:dateTime or RFC3339? Aug 18 16:19:50 RFC3339 is dated July 2002 ... Aug 18 16:19:54 Right --- and you might be able to understand xsd:dateTime without reading all of xml schema, you wouldn't be confident of it Aug 18 16:20:25 W3C Recommendation 28 October 2004 ... but that's 2nd ed... Aug 18 16:20:47 W3C Recommendation 02 May 2001 Aug 18 16:22:10 I don't see a BNF in http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#dateTime ... Aug 18 16:22:43 yeah, appendix D of the current xml schema datatypes document seems a little scanty, actually Aug 18 16:23:28 ah... 2nd ed of http://www.w3.org/TR/xmlschema-2/#date is much more explicit about syntax. Aug 18 16:23:30 it's 1100 words but still doesn't give any examples Aug 18 16:23:35 still, it's given in prose and not BNF Aug 18 16:24:17 sections 3.2.9 through 3.2.14 seem to be the relevant ones around #date Aug 18 16:24:29 which is another 2200 words Aug 18 16:24:42 wow... they changed the canonical form of date from always-Z to timezone-allowed between 1st edition and 2nd edition Aug 18 16:25:01 Kragen, DanC, these are very good analyses Aug 18 16:25:21 could I ask you to summarize the pros/cons for each in a new section at end of http://microformats.org/wiki/datetime-design-pattern Aug 18 16:25:22 ? Aug 18 16:25:58 rfc 3339 is 4000 words, excluding the last two pages of boilerplate. Aug 18 16:26:31 so it's actually longer than the datetime-relevant parts of XSD but it seems much more rigorous and clear Aug 18 16:28:37 my advice is: normatively cite both, and claim they specify the same syntax, and let anybody who discovers otherwise send you a bug report with a test case Aug 18 16:29:12 danc: nice hack

The RFC3339 has a mandatory TIME portion of the DATE-TIME. Some vCard/iCalendar DATE-TIME stamps can omit the TIME. For instance, DTSTART, if that is a full day event, then you can omit the time. BDAY in vCard can be respresented by only a DATE. I like the idea of restricting the possible date formats, but i think that TIME should be optional, which it isn't in RFC3339. - brian suda

RFC 3339 allows lowercase 't' and 'z' while XSD doesn't. Specifying RFC 3339 plus 'T' and 'Z' MUST be caps will make them the same. - Joe Gregorio

---

A few questions: asked by CharlesBelov 16:57, 24 Apr 2007 (PDT), answered by JamesCraig on 15:58, 5 Jul 2007 (PDT).

  1. Would it make more sense for documenting the alternative codings pitting the abbr tag vs. other tags to be on this page? Answer: That documentation should go on the assistive-technology-abbr-results page.
  2. Would using the title attribute of the abbr tag to encode the machine-readable date in fact cause a failure of WCAG 2.0 Accessibility? What about USA Section 508? It does appear to violate Technique for WCAG 2.0 H28: Providing definitions for abbreviations by using the abbr and acronym elements, although that is a supporting document and does not have the force of a guideline. Answer: Yes, it appears that is in violation of WCAG, 508, et al, so alternatives are being discussed on the assistive-technology-abbr-results page.
  3. In order to maintain accessibility, would it make sense to enclose the machine-readable date in a span with a style of "display:none" instead of using the abbr tag? Answer: please refer to and add any suggestions to assistive-technology-abbr-results.
  4. For that matter, wouldn't you want to style such an abbr tag with text-decoration:none to hide that an abbr tag was used? Otherwise, visitors might cursor over the time, see the machine time, and be annoyed that their time was wasted or else be confused. And I don't think you can suppress the title from coming up if the human-readable time was inadvertently hovered. Answer: Microformats should not rely on CSS in order to work properly, but again, that discussion can be found here: assistive-technology-abbr-results.

Code

The following regular expression (parsed VERBOSE) should break apart a datetime and cover many lightly broken cases seen in the wild. This has been tested under Python.

^ (?P\d\d\d\d) ([-])?(?P\d\d) ([-])?(?P\d\d) ( (T|\s+) (?P\d\d) ( ([:])?(?P\d\d) ( ([:])?(?P\d\d) ( ([.])?(?P\d+) )? )? )? )? ( (?PZ) | (?P[-+]) (?P\d\d) ([:])?(?P\d\d) )? $

Other Proposals

This section needs a lot of clean-up. Proposals that have been relatively rejected need to be move to another section (or perhaps page), along with succinct summaries as to why they are untenable/infeasible/undesirable.

Remaining proposals probably need to be moved to proper brainstorming pages where they can be considered in a broader context.

Links to all proposals (whether relatively rejected or tentatively being considered) should be kept in this page for comparison purposes for this use case.

Tantek 04:50, 4 Sep 2008 (PDT)

strtime instructions as class names

Proposal by DavidLaban (alsuren on IRC) on 8 Jun 2008 It might be possible to have a slightly more readable/extensible/elegant format:

16 March 1987

Notes:

  1. Underscores are used to replace whitespace, because otherwise the the formatting string will be split into an unordered set of class attributes by many parsers (thanks go to bogdanlazarsb and gsnedders on irc for explaining this to me).
  2. Some subset of the placeholders should be chosen from those which are supported by both python http://docs.python.org/lib/module-time.html and php http://uk3.php.net/manual/en/function.strftime.php
  3. A name for the class should be decided upon. strtime might not be the best name.
  4. Measures should be taken to avoid the format string accidentally conflicting with other valid classes (In the above example, I have prefixed it with the string "format:")
  5. It might be sensible (when parsing) to strip excess whitespace from the format string and contents. This is not done in this example.
  6. Example python code follows.

date = (1987,03,16,0,0,0,0,0,0) format = " %d %B %Y "

To encode:

classes = ["strtime"] encoded_format = "format:" + format.replace(' ', '_') classes.append(encoded_format) content = time.strftime(format, birthday)

... dump classes and content into your document however you want

To decode (assuming that you have managed to extract class and format from the document already):

if "strtime" in classes: possible_formats = [ item for item in classes if item.startswith('format:') ] assert len(possible_formats) == 1 format = possible_formats[0].strip('format:').replace('_', ' ') date = time.strptime(content, format)

problems with strtime proposal

  1. Possible abuse of the class attribute. microformats limit the use of the class attribute to marking up additional semantics about the data, not for (potentially) arbitrary processing/programming instructions
    • HTML 4.01 Recommendation defines the class attribute as being "for general purpose processing by user agents". TobyInk 13:21, 8 Jun 2008 (PDT)
  2. Requires authors to think like programmers. The larger problem is that the proposal asks web authors to think like programmers, which severely limits the number of web authors which will be able to use the technique, since the vast majority of web authors are not programmers and have never heard of "strtime", whereas most authors (even people) on the web have seen dates like 2005-06-20 and easily understand what they mean.

In general, any publishing method that requires the author to think like a programmer is a non-starter. It is a much more of a barrier than simply using ISO8601/RFC3339, and that barrier is a far worse tradeoff than the duplication / DRY violation compromise.Tantek 09:52, 8 Jun 2008 (PDT)

Machine-data in class

The BBC (uf-dev archive, 20/06/08, "Using class for non-human data") has proposed as an alternative to the empty span and title solution to use the class name in the following way:

10 o'clock on the 10th

Pros:

Cons:

Discussion:

Experimental Parser Support

Cognition 0.1 alpha 10 will include experimental support for this pattern, and the Cognition web service already does. Notes:

date and time separation using value excerption

Moved to value excerption pattern brainstorming which is a better way of thinking about this.

HTML 5 <time> Element

See hCalendar issues

Plain Old English alternative to ISO date

Example (in English):

1/25

January 25th, 2008

If lang="en-us", the format of the date used in the title attribute must conform to dates writing rules in American English.

Example (in French):

25/1

If lang="fr", the format of the date used in the title attribute must conform to date writing rules in French.

Benefits

Disadvantages

Most extracted from discussion below.

Discussion

Notes

<object> element to represent dates

The idea was to do something like this:

January 25

issues

Open issues related to this proposal. Some may require additional information to be acted upon / resolved.

resolved issues

Issues raised and resolved related to this proposal. Issues that are misconceptions (e.g. easily refuted by citing the HTML4 specification) are resolved by moving to the separate misconceptions section below with explanation/citation for why they are misconceptions.

misconceptions

external application only

This is false. From the HTML4.01 section on OBJECT:

Still others [other objects] may not require additional implementation information, i.e., the user agent itself may already know how to render that type of data (e.g., GIF images).

Thus browsers may render OBJECTs themselves, like images, and external applications are not necessarily required. For example IE5/Mac supported native rendering of PNG images even as objects, while other browsers at the time (2000) which supported OBJECT, only rendered PNG images via external plugins.

need width and height

This is false. Per the HTML4.01 section on OBJECT, the width and height attributes are "#IMPLIED" not "#REQUIRED".

Individual markup of each date/time component

A variant of this idea has been documented into a specific proposal and is being tested. Please see the value excerption pattern brainstorming: date and type separation and value-excerption-dt-separation-test page for updated details. Tantek 22:05, 24 February 2009 (UTC)

A combination of suggestions that originated from this post

This is suggested as a complementary alternative to datetime-design-pattern, when the use of the pattern is not possible due to accessibility reasons.

suggested class names:

For a complete datetime:

October 5, 2004 at 6PM

date maybe not required since dtstart IS a date.

For a duration:

1: 3: 42
  • An example of this is also documented on ISO-31-1

Issues

  • the internationalization issue is not addressed, but it is limited to the month of the year.
  • Tonnes and tonnes of nested elements to mark up something that's essentially very simple. Microformats are "for humans first, machines second", but this suggestion appears to be friendly to neither! TobyInk 02:21, 12 Aug 2008 (PDT)
    • Also worth pointing out that the complexity issue applies less to durations. With durations, most people will probably only want to use a combination of 1 to 3 time components (e.g. d+h, h+min+s, h+min, min+s, d only, h only, min only, s only) But with datetimes, they're likely to want to specify at least five components (y+m+d+h+min) and often also the timezone (seconds, and fractions thereof, are not especially useful for the majority of use cases). So marking up the time components might be OK for durations, but becomes onerous for datetimes.

See Also