All Projects → github → Time Elements

github / Time Elements

Licence: mit
Web component extensions to the standard <time> element.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Time Elements

Swiss
🇨🇭Functional custom elements
Stars: ✭ 169 (-92.71%)
Mutual labels:  web-components, custom-elements
Nutmeg
Build, test, and publish vanilla Web Components with a little spice
Stars: ✭ 111 (-95.21%)
Mutual labels:  web-components, custom-elements
Aybolit
Lightweight web components library built with LitElement.
Stars: ✭ 90 (-96.12%)
Mutual labels:  web-components, custom-elements
Task Lists Element
Drag and drop task list items.
Stars: ✭ 73 (-96.85%)
Mutual labels:  web-components, custom-elements
Ion Phaser
A web component to use Phaser Framework with Angular, React, Vue, etc 🎮
Stars: ✭ 152 (-93.44%)
Mutual labels:  web-components, custom-elements
Use Custom Element
Custom hook to bridge Custom Elements (Web Components) to React.
Stars: ✭ 77 (-96.68%)
Mutual labels:  web-components, custom-elements
Vanilla Hamburger
Animated hamburger menu icons for modern web apps (1.8 KB) 🍔
Stars: ✭ 110 (-95.25%)
Mutual labels:  web-components, custom-elements
Details Dialog Element
A modal dialog that's opened with <details>.
Stars: ✭ 603 (-73.99%)
Mutual labels:  web-components, custom-elements
Html Include Element
Easily include external HTML into your pages.
Stars: ✭ 143 (-93.83%)
Mutual labels:  web-components, custom-elements
Elm Canvas
A canvas drawing library for Elm
Stars: ✭ 124 (-94.65%)
Mutual labels:  web-components, custom-elements
File Input
A better <input type="file">
Stars: ✭ 59 (-97.45%)
Mutual labels:  web-components, custom-elements
Markdown Toolbar Element
Markdown formatting buttons for text inputs.
Stars: ✭ 160 (-93.1%)
Mutual labels:  web-components, custom-elements
Custom Elements Ts
Create native custom elements using Typescript
Stars: ✭ 52 (-97.76%)
Mutual labels:  web-components, custom-elements
Auto Check Element
An input element that validates its value with a server endpoint.
Stars: ✭ 85 (-96.33%)
Mutual labels:  web-components, custom-elements
Paper Timezone
Polymer based timezone selection component
Stars: ✭ 19 (-99.18%)
Mutual labels:  timezone, web-components
Dataformsjs
🌟 DataFormsJS 🌟 A minimal JavaScript Framework and standalone React and Web Components for rapid development of high quality websites and single page applications.
Stars: ✭ 95 (-95.9%)
Mutual labels:  web-components, custom-elements
Emoji Picker Element
A lightweight emoji picker for the modern web
Stars: ✭ 587 (-74.68%)
Mutual labels:  web-components, custom-elements
Xy Ui
🎨面向未来的原生 web components UI组件库
Stars: ✭ 603 (-73.99%)
Mutual labels:  web-components, custom-elements
Image Crop Element
A custom element for cropping a square image. Returns x, y, width, and height.
Stars: ✭ 115 (-95.04%)
Mutual labels:  web-components, custom-elements
Omi
Front End Cross-Frameworks Framework - 前端跨框架跨平台框架
Stars: ✭ 12,153 (+424.29%)
Mutual labels:  web-components, custom-elements

<time> element extensions

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:

<local-time datetime="2014-04-01T16:30:00-08:00">
  April 1, 2014 4:30pm
</local-time>

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.

<local-time datetime="2014-04-01T16:30:00-08:00">
  1 Apr 2014 21:30
</local-time>

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.

$ npm install @github/time-elements

Usage

This component provides three custom subtypes of the standard HTML <time> element. All custom time elements MUST have a datetime attribute set to an ISO 8601 formatted timestamp.

relative-time

A relative time-ago-in-words description can be generated by using the relative-time element extension.

Add a <relative-time> element to your markup. Provide a default formatted date as the element's text content (e.g. April 1, 2014).

<relative-time datetime="2014-04-01T16:30:00-08:00">
  April 1, 2014
</relative-time>

Depending on how far in the future this is being viewed, the element's text will be replaced with one of the following formats:

  • 6 years from now
  • 20 days from now
  • 4 hours from now
  • 7 minutes from now
  • just now
  • 30 seconds ago
  • a minute ago
  • 30 minutes ago
  • an hour ago
  • 20 hours ago
  • a day ago
  • 20 days ago
  • on Apr 1, 2014

So, a relative date phrase is used for up to a month and then the actual date is shown.

time-until

You can use time-until to always display a relative date that's in the future. It operates much like <relative-time>, except in the reverse, with past events shown as just now and future events always showing as relative:

  • 10 years from now
  • 20 days from now
  • 6 hours from now
  • 20 minutes from now
  • 30 seconds from now
  • just now

Add a <time-until> element to your markup. Provide a default formatted date as the element's text content (e.g. April 1, 2024).

<time-until datetime="2024-04-01T16:30:00-08:00">
  April 1, 2024
</time-until>

time-ago

An always relative time-ago-in-words description can be generated by using the time-ago element extension. This is similar to the relative-time extension. However, this will never switch to displaying the date. It strictly shows relative date phrases, even after a month has passed.

<time-ago datetime="2012-04-01T16:30:00-08:00">
  April 1, 2014
</time-ago>

For example, if this markup is viewed two years in the future, the element's text will read 2 years ago.

Micro format

The optional format="micro" attribute shortens the descriptions to 1m, 1h, 1d, 1y.

<time-ago datetime="2012-04-01T16:30:00-08:00" format="micro">
  April 1, 2014
</time-ago>

local-time

This custom time extension is useful for formatting a date and time in the user's preferred locale format.

<local-time datetime="2014-04-01T16:30:00-08:00"
    month="short"
    day="numeric"
    year="numeric"
    hour="numeric"
    minute="numeric">
  April 1, 2014 4:30PM PDT
</local-time>

When this markup is viewed in a CDT timezone, it will show Apr 1, 2014 6:30PM. If it's viewed in a browser with European date preferences, it will read 1 Apr 2014 18:30.

Options

Attribute Options Description
datetime ISO 8601 date Required date of element 2014-06-01T13:05:07Z
year 2-digit, numeric Format year as 14 or 2014
month short, long Format month as Jun or June
day 2-digit, numeric Format day as 01 or 1
weekday short, long Format weekday as Sun or Sunday
hour 2-digit, numeric Format hour as 01 or 1
minute 2-digit, numeric Format minute as 05 or 5
second 2-digit, numeric Format second as 07 or 7
time-zone-name short, long Display time zone as GMT+1 or by its full name

Browser Support

Browsers without native custom element support require a polyfill.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

See Also

Most of this implementation is based on Basecamp's local_time component. Thanks to @javan for open sourcing that work and allowing for others to build on top of it.

@rmm5t's jquery-timeago is one of the old time-ago-in-words JS plugins.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].