MCPcopy Create free account
hub / github.com/ThatGuySam/doesitarm / getRelativeTime

Function getRelativeTime

helpers/parse-date.js:13–21  ·  view source on GitHub ↗
(d1, d2 = new Date())

Source from the content-addressed store, hash-verified

11const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' })
12
13const getRelativeTime = function (d1, d2 = new Date()) {
14 var elapsed = d1 - d2
15
16 // "Math.abs" accounts for both "past" & "future" scenarios
17 for (var u in units)
18 if (Math.abs(elapsed) > units[u] || u == 'second')
19 return rtf.format(Math.round(elapsed/units[u]), u)
20
21}
22
23export function makeLastUpdatedFriendly ( lastUpdated ) {
24

Callers 1

parse-date.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected