relative-time-element
relative-time-element copied to clipboard
RelativeTimeElement: Progressive time update intervals
When updating nowElements
, figure out how far away in time the nearest one is
to ensure timely updates:
If an element is within
- one minute from now, update a second after last run
- one hour from now - update a minute after last run
- more than one hour from now - update 10 minutes after last run
Switching to setTimeout ensures that with a lot of attached instances, where a run might take a while, we won't schedule the next run until after all elements have been updated.
Also fire a relative-time-updated
event if textContent
changes in case
this needs to be acted on.