relative-time-element

Web component extensions to the standard

README

<relative-time> element


Formats a timestamp as a localized string or as relative text that auto-updates in the user's browser.

This allows the server to cache HTML fragments containing dates and lets the browser choose how to localize the displayed time according to the user's preferences. For example, the server may have cached the following generated markup:

  1. ``` html
  2. <local-time datetime="2014-04-01T16:30:00-08:00">
  3.   April 1, 2014 4:30pm
  4. </local-time>
  5. ```

Every visitor is served the same markup from the server's cache. When it reaches the browser, the custom local-time JavaScript localizes the element's text into the local timezone and formatting.

  1. ``` html
  2. <local-time datetime="2014-04-01T16:30:00-08:00">
  3.   1 Apr 2014 21:30
  4. </local-time>
  5. ```

Dates are displayed before months, and a 24-hour clock is used, according to the user's browser settings.

If the browser's JavaScript is disabled, the default text served in the cached markup is still displayed.

Installation


Available on npm as [@github/time-elements](https://www.npmjs.com/package/@github/time-elements).

  1. ```
  2. $ npm install @github/time-elements
  3. ```

Usage


This component provides three custom subtypes of the standard HTML `