mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Rename parseGithubDate to parseDate
This commit is contained in:
parent
95b692a3be
commit
a5333b1939
6 changed files with 8 additions and 8 deletions
33
helpers/parse-date.js
Normal file
33
helpers/parse-date.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// in miliseconds
|
||||
const units = {
|
||||
year : 24 * 60 * 60 * 1000 * 365,
|
||||
month : 24 * 60 * 60 * 1000 * 365/12,
|
||||
day : 24 * 60 * 60 * 1000,
|
||||
hour : 60 * 60 * 1000,
|
||||
minute: 60 * 1000,
|
||||
second: 1000
|
||||
}
|
||||
|
||||
const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' })
|
||||
|
||||
const getRelativeTime = function (d1, d2 = new Date()) {
|
||||
var elapsed = d1 - d2
|
||||
|
||||
// "Math.abs" accounts for both "past" & "future" scenarios
|
||||
for (var u in units)
|
||||
if (Math.abs(elapsed) > units[u] || u == 'second')
|
||||
return rtf.format(Math.round(elapsed/units[u]), u)
|
||||
|
||||
}
|
||||
|
||||
export default function (rawDate) {
|
||||
|
||||
const date = new Date(rawDate)
|
||||
|
||||
return {
|
||||
date,
|
||||
raw: rawDate,
|
||||
timestamp: date.getTime(),
|
||||
relative: getRelativeTime(date)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue