forked from blisstown/campfire
federating my verse (iceshrimp & mastodon API compat, read-only)
This commit is contained in:
parent
8dc8190cdf
commit
da93978820
67 changed files with 2743 additions and 649 deletions
23
src/time.js
Normal file
23
src/time.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
const denoms = [
|
||||
{ unit: 's', min: 0 },
|
||||
{ unit: 'm', min: 60 },
|
||||
{ unit: 'h', min: 60 },
|
||||
{ unit: 'd', min: 24 },
|
||||
{ unit: 'w', min: 7 },
|
||||
{ unit: 'y', min: 52 },
|
||||
];
|
||||
|
||||
export function shorthand(date) {
|
||||
let value = (new Date() - date) / 1000;
|
||||
let unit = 's';
|
||||
let index = 0;
|
||||
while (index < denoms.length - 1) {
|
||||
if (value < denoms[index + 1].min) break;
|
||||
index++
|
||||
value /= denoms[index].min;
|
||||
unit = denoms[index].unit;
|
||||
}
|
||||
if (value > 0)
|
||||
return Math.floor(value) + unit + " ago";
|
||||
return "in " + Math.floor(value) + unit;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue