Giter Club home page Giter Club logo

relative-time-element's Introduction

<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:

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

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

<relative-time datetime="2014-04-01T16:30:00-08:00">
  1 Apr 2014 21:30
</relative-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/relative-time-element.

$ npm install @github/relative-time-element

This element uses the Intl.DateTimeFormat & Intl.RelativeTimeFormat APIs, which are supported by all modern JS engines. If you need to support an older browser, you may need to introduce a polyfill for Intl.DateTimeFormat & Intl.RelativeTimeFormat.

Usage

Add a <relative-time> element to your markup. Provide a default formatted date as the element's text content (e.g. April 1, 2014). It also MUST have a datetime attribute set to an ISO 8601 formatted timestamp.

<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.

Attributes

Property Name Attribute Name Possible Values Default Value
datetime datetime string -
format format 'datetime'|'relative'|'duration' 'auto'
date - Date | null -
tense tense 'auto'|'past'|'future' 'auto'
precision precision 'year'|'month'|'day'|'hour'|'minute'|'second' 'second'
threshold threshold string 'P30D'
prefix prefix string 'on'
formatStyle format-style 'long'|'short'|'narrow' *
second second 'numeric'|'2-digit'|undefined undefined
minute minute 'numeric'|'2-digit'|undefined undefined
hour hour 'numeric'|'2-digit'|undefined undefined
weekday weekday 'short'|'long'|'narrow'|undefined **
day day 'numeric'|'2-digit'|undefined 'numeric'
month month 'numeric'|'2-digit'|'short'|'long'|'narrow'|undefined ***
year year 'numeric'|'2-digit'|undefined ****
timeZoneName time-zone-name 'long'|'short'|'shortOffset'|'longOffset' |'shortGeneric'|'longGeneric'|undefined undefined

*: If unspecified, formatStyle will return 'narrow' if format is 'elapsed' or 'micro', 'short' if the format is 'relative' or 'datetime', otherwise it will be 'long'.

**: If unspecified, month will return the same value as formatStyle whenever format is 'datetime', otherwise it will be 'short'.

***: If unspecified, weekday will return the same value as formatStyle whenever format is 'datetime', otherwise it will be undefined.

****: If unspecified, year will return 'numeric' if datetime represents the same year as the current year. It will return undefined if unspecified and if datetime represents a different year to the current year.

datetime (string)

This is the datetime that the element is meant to represent. This must be a valid ISO8601 DateTime. It is also possible to use the date property on the element to set the date. el.date expects a Date object, while el.datetime expects a string. Setting one will override the other.

<relative-time datetime="2014-04-01T16:30:00-08:00" tense="past">
  April 1, 2038 <!-- Will display "now" until April 1 2038 at 16:30:01! -->
</relative-time>
<script>
  const el = document.querySelector('relative-time')
  console.assert(el.date.toISOString() === el.datetime)
  el.date = new Date()
  console.assert(el.datetime !== "2014-04-01T16:30:00-08:00")
</script>
format ('datetime'|'relative'|'duration'|'auto'|'micro'|'elapsed')

Format can be either 'datetime', 'relative', or 'duration'. It can also be one of several deprecated formats of 'auto', 'micro', or 'elapsed'.

The default format is auto, which is an alias for relative. In the next major version this will be relative.

format=datetime

The datetime format will display a localised datetime, based on the other properties of the element. It uses Intl.DateTimeFormat to display the datetime in a localised format.

Unless specified, it will consider weekday to be 'long', month to be 'long', and 'year' to be numeric if the datetime is the same as the given year. Overriding formatStyle will change both weekday and month default values. Examples of this format with the default options and an en locale:

  • Wed, 26 Aug 2021
  • Sat, 31 Dec (assuming the datetime is same year as the current year)
format=relative

The default relative format will display dates relative to the current time (unless they are past the threshold value - see below). The values are rounded to display a single unit, for example if the time between the given datetime and the current wall clock time exceeds a day, then the format will only output in days, and will not display hours, minutes or seconds. Some examples of this format with the default options and an en locale:

  • in 20 days
  • 20 days ago
  • in 1 minute
  • on 31 Aug (assuming the current date is the same year as the current year, and is more than 30 days away from 31 Aug)
  • on 26 Aug 2021 (assuming the current date is more than 30 days away from 26 Aug 2021)
format=duration

The duration format will display the time remaining (or elapsed time) from the given datetime, counting down the number of years, months, weeks, days, hours, minutes, and seconds. Any value that is 0 will be omitted from the display by default. Examples of this format with the default options and an en locale:

  • 4 hours, 2 minutes, 30 seconds
  • 4 hours
  • 8 days, 30 minutes, 1 second
Deprecated Formats
format=elapsed

This is similar to the format=duration, except the formatStyle defaults to narrow. Code that uses format=elapsed should migrate to format=duration formatStyle=narrow, as it will be removed in a later version.

format=auto

This is identical to format=relative. Code that uses format=auto should migrate to format=relative as this will be the new default in a later version.

format=micro

The micro format which will display relative dates (within the threshold) in a more compact format. Similar to relative, the micro format rounds values to the nearest largest value. Additionally, micro format will not round lower than 1 minute, as such a datetime which is less than a minute from the current wall clock time will display '1m'.

Code that uses format=micro should consider migrating to format=relative (perhaps with formatStyle=narrow), as format=micro can be difficult for users to understand, and can cause issues with assistive technologies. For example some screen readers (such as VoiceOver for mac) will read out 1m as 1 meter.

Cheatsheet
format=datetime format=relative format=duration format=micro format=elapsed
Wed 26 May 2024 in 2 years 2 years, 10 days, 3 hours, 20 minutes, 8 seconds 2y 2y 10d 3h 20m 8s
Wed 26 Aug 2021 2 years ago 2 years, 10 days, 3 hours, 8 seconds 2y 2y 10d 3h 8s
Jan 15 2023 in 30 days 30 days, 4 hours, 20 minutes, 8 seconds 30d 30d 4h 20m 8s
Dec 15 2022 21 minutes ago 21 minutes, 30 seconds 21m 21m 30s
Dec 15 2022 37 seconds ago 37 seconds 1m 37s
tense ('auto'|'past'|'future', default: auto)

If format is 'datetime' then this value will be ignored.

Tense can be used to prevent duration or relative formatted dates displaying dates in a tense other than the one specified. Setting tense=past will always display future relative dates as now and duration dates as 0 seconds, while setting it to future will always display past dates relative as now and past duration dates as 0 seconds.

For example when the given datetime is 40 seconds behind of the current date:

tense= format=duration format=relative
future 0s now
past 40s 40s ago
auto 40s 40s ago
<relative-time datetime="2038-04-01T16:30:00-08:00" tense="past">
  April 1, 2038 <!-- Will display "now" until April 1 2038 at 16:30:01! -->
</relative-time>
<relative-time datetime="1970-04-01T16:30:00-08:00" tense="future">
  April 1, 2038 <!-- Will display "now" unless you had a time machine and went back to 1970 -->
</relative-time>

precision ('year'|'month'|'day'|'hour'|'minute'|'second', default: 'second')

If format is datetime then this value will be ignored.

Precision can be used to limit the display of an relative or duration formatted time. By default times will display down to the second level of precision. Changing this value will truncate the display by zeroing out any unit lower than the given unit, as such units smaller than the given unit won't be displayed during duration, and relative will display now if the time away from the current time is less than the given precision unit.

precision= format=duration
seconds 2y 6m 10d 3h 20m 8s
minutes 2y 6m 10d 3h 20m
hours 2y 6m 10d 3h
days 2y 6m 10d
months 2y 6m
years 2y
precision= format=relative
seconds 25 seconds
minutes now
hours now
days now
months now
years now
threshold (string, default: P30D)

If tense is anything other than 'auto', or format is 'relative' (or the deprecated 'auto' or 'micro' values), then this value will be ignored.

Threshold can be used to specify when a relative display (e.g. "5 days ago") should turn into an absolute display (i.e. the full date). This should be a valid ISO8601 Time Duration. If the difference between the current time and the specified datetime is more than the duration, then the date will be displayed as an absolute value (i.e. the full date), otherwise it will be formatted to a relative display (e.g. "5 days ago").

The default value for this is P30D, meaning if the current time is more than 30 days away from the specified date time, then an absolute date will be displayed.

<relative-time datetime="1970-04-01T16:30:00-08:00" threshold="P100Y">
  <!-- Will display "<N> years ago" until 2070 when it will display "on April 1, 1970" -->
</relative-time>
<relative-time datetime="1970-04-01T16:30:00-08:00" threshold="P0S">
  <!-- Will always display "on April 1, 1970" -->
</relative-time>
prefix (string, default: 'on')

If tense is anything other than 'auto', or format is anything other than 'relative' (or the deprecated 'auto' or 'micro' values), then this value will be ignored.

When formatting an absolute date (see above threshold for more details) it can be useful to prefix the date with some text. The default value for this is on but it can be any string value, an will be prepended to the date.

<relative-time datetime="1970-04-01T16:30:00-08:00" prefix="this happened on">
  <!-- Will always display "this happened on April 1, 1970" -->
</relative-time>
formatStyle ('long'|'short'|'narrow', default: 'narrow'|'long')

This will used to determine the length of the unit names. This value is passed to the Intl objects as the style option. Some examples of how this can be used:

format= formatStyle= Display
relative long in 1 month
relative short in 1 mo.
relative narrow in 1 mo.
duration long 1 month, 2 days, 4 hours
duration short 1 mth, 2 days, 4 hr
duration narrow 1m 2d 4h
second, minute, hour, weekday, day, month, year, timeZoneName

For dates outside of the specified threshold, the formatting of the date can be configured using these attributes. The values for these attributes are passed to Intl.DateTimeFormat:

lang

Lang is a built-in global attribute. Relative Time will use this to provide an applicable language to the Intl APIs. If the individual element does not have a lang attribute then it will traverse upwards in the tree to find the closest element that does, or default the lang to en.

Browser Support

Browsers without native custom element support require a polyfill.

Browsers without native support for Intl.RelativeTimeFormat or Intl.DateTimeFormat (such as Safari 13 or Edge 18) will also need polyfills.

  • Chrome
  • Firefox
  • Safari (version 14 and above)
  • Microsoft Edge (version 79 and above)

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.

relative-time-element's People

Contributors

alpharomeomike avatar broccolinisoup avatar dependabot[bot] avatar dgraham avatar dgreif avatar dotpointer avatar feelepxyz avatar holman avatar idlewan avatar iiic avatar jonrohan avatar josepmartins avatar josh avatar keithamus avatar kkirsche avatar koddsson avatar lyricwulf avatar manuelpuyol avatar markmcspadden avatar meduzen avatar mislav avatar muan avatar nwalters512 avatar rafaeliga avatar schweinepriester avatar simonwaldherr avatar simurai avatar srt32 avatar theinterned avatar zenorocha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

relative-time-element's Issues

Compatibility broken with Web components 1.0.0

When used in Firefox, I get the following error:

TypeError: document.registerElement is not a function

screenshot from 2017-06-27 11-16-56

The polyfill with version 1.0.0 of web component assumes that window.customElements.define is used.

time-elements + Polymer 1.0 won't work

It seems that time-elements.js doesn't seem to work with Polymer 1.0. Couldn't really grasp what was wrong. Would be great if it was fixed/supported!

HTML Import

Any way you guys can make a time-elements.html file which simply imports the javascript file.

Add a file named: time-elements.html
the contents of that file should be exactly
<script src="./time-elements.js"></script>

This is the proper way to import web components because importing an html file twice does nothing while importing a javascript file twice will try to run the code twice.

Avoid is="" API

Safari 10 will be supporting Custom Elements soon, but won't support is="".

We should rewrite this extension without extending <time> and just do <relative-time> and <local-time>.

Hopefully we can get github.com updated long before so future Enterprise versions will be ready with this change. Unsure if the Polymer Custom Element polyfill will correctly cover a partial Custom Elements implementation.

To: @dgraham @mislav
CC: @notwaldorf @github/js

Travis CI

After this repo is public, we can setup Travis CI phantomjs builds.

Custom prefix for relative-time

I noticed that for <relative-time> which is further than 1 month ago we show example: on 14 April 2018

Would it be possible to add custom prefix, which if not specified would default to on (for backwards compatibility) but in case I could specify empty string so I would get just 14 April 2018?

Override content for local-time and default formatting

I found 2 problems: appending content in chrome and no default formatting

No default formatting:

Source:

<local-time datetime="2018-08-24T16:57:42.604Z">Aug 24, 2018 23:57:42</local-time>

Result:

<local-time datetime="2018-08-24T16:57:42.604Z" title="Aug 24, 2018, 11:57 PM GMT+7">Aug 24, 2018 23:57:42</local-time>

would be much easier to start if it would apply default formatting month="short" day="numeric" year="numeric" hour="numeric" minute="numeric" (or similar) and may be update-content=false to prevent updating content

Appending content in chrome:
Source:

<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>

Result:

<local-time datetime="2014-04-01T16:30:00-08:00" month="short" day="numeric" year="numeric" hour="numeric" minute="numeric" title="Apr 2, 2014, 7:30 AM GMT+7">Apr 2, 2014 7:30 AMApril 1, 2014 4:30PM PDT</local-time>

add an attribute to accept millisecond format time

In some case we receive millisecond format time from server, currently I have to construct a date object and convert it into a string of acceptable format in a customized filter, that's really inconvenient. So have you guys considered to define a different attribute to accept time of this format? like time="1414579265159"

Use of `from now` carries vague implication of future tense

Had a situation on this PR. As I filled in the comment, I saw:

myii requested review from aboe76 and noelmcloughlin 3 minutes from now

To be fair, this soon became:

myii requested review from aboe76 and noelmcloughlin 4 minutes ago

So probably just a glitch. Just to be clear, from now connotes a future event, as mentioned on this page.

time-ago wrong calcul

For current date 2015-02-23T00:00:00.000Z (like)

The following html :

Give this result :
117y

Or it's should give 115 or maybe 116 not 117 !

Note : for date 002-02-01T00:00:00.000Z It's even more obvious.

Make "ago" optional for time-ago

What do you think about making "ago" optional for time-ago? It's often useful to get a human-readable time span and combine it with custom suffix, e.g.: 2 days since the last meeting, 10 years of experience. moment.js supports similar feature via a boolean argument to fromNow(true) method.

Mixed languages in '<relative-time>'

Issues lists on GitHub have relative times displayed in two languages. For example, my os/browser is set to the Slovak language and when I open a GitHub issues list, some relative times are displayed as translated (red) and some in English (blue) - see the attached screenshot.

Browser: Google Chrome 74.0.3729.169
OS: macOS Mojave 10.14.4

github

Jalali Calendar

Unfortunately all of new elements (time, date-picker, ...) don't implement Jalali calendar in them...
We should do something about it.

Drop moment.js dependency

We expose a strftime format expression rather than the moment tokens. This means we aren't coupled to moment.js. Removing moment.js would give this component and overall smaller footprint as well as make it easier to install.

Develop a true Web Component version of time-elements

I'm trying to use time-elements in an application built on top of Polymer (2.0) and Web Components and I can't seem to get this to work since there is no real web component defined for these custom HTML tags. I know this is added to the Web Components website but it only has the .js file and no HTML files to import. My request is two-fold:

  1. Make full-blown Web Components for each custom HTML tag (eg. <relative-time>, <local-time>, etc.) with HTML imports.
  2. Is there a way to properly use the current implementation in a Polymer 2.0 Web Component?

Thank you for your work!

Edit: I forgot to mention that I'm relatively new to Web Components and Polymer so it's very possible that I'm missing something and time-elements in its current form is already a real web component and I just don't realize it.

Bug displaying 'in 3 hours'

Looks like there could be a bug here, if you are using this library on the Github User Feed Page.

I believe this should be 3 hours ago, as opposed to in 3 hours unless github is predicting the future.

Mind blown

see screenshot below:

Screenshot 2019-08-28 at 13 51 10

"Maximum call stack size exceeded error" with 3.0.9

It looks like the update to 3.0.9 introduced an infinite loop in the <relative-time /> element.

Repro Link:
https://codesandbox.io/s/thirsty-joliot-44k9p
Repro Steps:

  • Open link
  • Open browser console
  • Refresh
Uncaught RangeError: Maximum call stack size exceeded.
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at HTMLElement.attributeChangedCallback (time-elements-legacy.js:248)
    at evaluate (index.js? [sm]:6)
    at Jn (eval.js:61)
    at e.value (transpiled-module.ts:980)
    at e.value (manager.ts:361)
    at t (transpiled-module.ts:958)
    at loadResources (index.html:3)

Compare to https://codesandbox.io/s/wizardly-dew-7pih0 which is using 3.0.8 and does not have the issue.

Here is the relevant code:

if (title && (!currentTitle || currentTitle === oldTitle)) {
        this.setAttribute('title', title);
      }

which I think was modified in this PR:
#129

Expose time formatting

The source code contains an implementation of strftime and a few functions that use it but there's no way to access it directly. It would be nice if you could use it to customize the format of the title attribute and other strings.

Translation support

If this element supports translation, it would be great!

Example:
<time datetime="2015-02-23T09:51:57Z" is="relative-time" lang="ja-jp">Feb 23, 2015</time>

Register bower package

Once the repo is public.

$ bower register time-elements https://github.com/github/time-elements.git

Performance

Not using semicolon for end of line is terrible for performance.

tell how to properly import this into other webcomponents

Somewhat related to #81. Right now polymer lint will complain

 warning [undefined-elements] - The element relative-time is not defined

If I just have this at the end of modules:

 ...
 <script src="../bower_components/time-elements/time-elements.js"></script>
</dom-module>

Formatting not working on page reload (looking for fallback)

On an initial page load or page reload, the formatting is not working (Using Rails + Turbolinks). I used to solve this by calling updateNowElements directly but now that Rails 6 switch to webpacker, i'd like to know how to access updateNowElements after importing time-elements via

import timeElements from 'time-elements/dist/time-elements.js'

[question] Manual trigger

Hi guys,

I wasn't able to get this to work to elements that were created after the document has sent the ready event. Is there a way to manually transform an element, or to rerun the search on the page to parse the <time> elements again?

Thanks!

How to use directly without npm?

I'd like to just do <script src=... without hosting my own time-elements.js file. Can't seem to find anything like this in the README.

How to do it?

Can't get <relative-time> working with PWA & LitElement

I have been using time-elements for a Polymer 2.0 app successfully and when I came to upgrade to polymer 3.0 I decided to go straight to PWA

However I can't get time-elements working even though I'm passing the same data as before.

I've used NPM to get hold of the code, and it's listed in package.json and I can see it in node_modules

I've added an import to my component
import 'time-elements/dist/time-elements.js';

and I'm using the tag as normal way
<relative-time datetime="${event.created}"></relative-time> in the _render() method.

The code is loaded when I access the page but the time doesn't seem to render, and nothing written to the console.

I've probably done something stupid but I'd appreciate some help, please.

Relative time

Is there any way to make it possible to display "on the 7 of March" instead of "on 7 March" ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.