Blockchain explorer for Ethereum based network and a tool for inspecting and analyzing EVM based blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
blockscout/apps/block_scout_web/assets/js/lib/from_now.js

28 lines
780 B

import $ from 'jquery'
import moment from 'moment'
moment.relativeTimeThreshold('M', 12)
moment.relativeTimeThreshold('d', 30)
moment.relativeTimeThreshold('h', 24)
moment.relativeTimeThreshold('m', 60)
moment.relativeTimeThreshold('s', 60)
moment.relativeTimeThreshold('ss', 1)
export function updateAllAges ($container = $(document)) {
$container.find('[data-from-now]').each((i, el) => tryUpdateAge(el))
return $container
}
function tryUpdateAge (el) {
if (!el.dataset.fromNow) return
const timestamp = moment(el.dataset.fromNow)
if (timestamp.isValid()) updateAge(el, timestamp)
}
function updateAge (el, timestamp) {
const fromNow = timestamp.fromNow()
if (fromNow !== el.innerHTML) el.innerHTML = fromNow
}
updateAllAges()
setInterval(updateAllAges, 1000)