alphagov / government-frontend

Serves government pages on GOV.UK
https://docs.publishing.service.gov.uk/apps/government-frontend.html
MIT License
50 stars 17 forks source link

Add <time> metadata to publication dates. #1904

Open edent opened 3 years ago

edent commented 3 years ago

Please can we add the <time> HTML element to things like publication dates and last updated dates?

Documentation: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time

This will allow users and machines to semanticly understand when a document was published/updated.

At the moment, the HTML is rendered as:

<div class="app-c-published-dates " lang="en">
    Published 21 April 2016
    <br>Last updated 21 July 2016
      — <a href="#history" class="app-c-published-dates__history-link govuk-link">see all updates</a>
</div>

Under this proposal, it would be:

<div class="app-c-published-dates " lang="en">
    Published <time datetime="2016-04-21">21 April 2016</time>
    <br>Last updated <time datetime="2016-07-21">21 July 2016</time>
      — <a href="#history" class="app-c-published-dates__history-link govuk-link">see all updates</a>
</div>

I think the relevant change needs to be made at: https://github.com/alphagov/government-frontend/blob/79e5c4d5862c321b404008ed734598ba70020d50/app/views/components/_published-dates.html.erb#L12

The metadata element just needs an ISO8601 timestamp passed to it - of any precision.

As per the comment at https://github.com/alphagov/open-standards/issues/75#issuecomment-723346578

chris-gds commented 2 years ago

The following code for time from Mozilla was tested across some common screen readers

<p>The Cure will be celebrating their 40th anniversary on <time datetime="2018-07-07">July 7</time> in London's Hyde Park.</p>

<p>The Cure will be celebrating their 40th anniversary on <time>July 7</time> in London's Hyde Park.</p>

<p>The Cure will be celebrating their 40th anniversary on <span datetime="2018-07-07">July 7</span> in London's Hyde Park.</p>

<p>The Cure will be celebrating their 40th anniversary on <span>July 7</span> in London's Hyde Park.</p>

Initial testing results

Screen Reader Browser Notes
JAWS 2020 Chrome Doesn't announce <time> or datetime=
NVDA 2021.2 Firefox Doesn't announce <time> or datetime=
Voiceover + macOS Chrome Doesn't announce <time> or datetime= also splits <time> into separate blocks similar to being wrapped <div>s
Narrator 21H1 Edge Doesn't announce <time> or datetime=

(Not a comment on use or next steps merely sharing outcomes from testing with assistive technology)

edent commented 2 years ago

Thanks @chris-gds - when you say "doesn't announce" - what do you mean? Does JAWS literally skip the content of the <time> element and read out "40th anniversary on in London's..."? Or is it that it doesn't give any extra semantic content? Thanks.

chris-gds commented 2 years ago

Hey @edent - at the moment yes it simply ignores it (this is my current understanding), see below: JAWS 2020, Edge (not Chrome this time)

(Screen recording of JAWs 2020 + Edge testing <time> examples)

https://user-images.githubusercontent.com/71266765/143436312-46c2b4fb-8811-4ddb-ab8b-85ff042bb6b8.mov

edent commented 2 years ago

Good to know it doesn't have any detrimental impact on screen readers. So it should improve the machine-readable semantics without causing any issues.

chris-gds commented 2 years ago

In theory yes, AT users don't appear to benefit nor does it cause issues.

I'm wondering now if we have any examples where this would be picked up (or used)? Are we thinking Google? Maybe Explore?

edent commented 2 years ago

There are a few examples where it could be useful.

chris-gds commented 2 years ago

All great examples to me, thanks for these.
(FWIW I was interested in this element from an accessibility POV so wanted to do a bit of testing)