mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-26 08:13:16 +00:00
Update app.js, add timeAgo util
This commit is contained in:
parent
6969bb5bb4
commit
ed09e54158
1 changed files with 25 additions and 0 deletions
25
resources/assets/js/app.js
vendored
25
resources/assets/js/app.js
vendored
|
@ -69,6 +69,31 @@ window.App.util = {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return new Intl.NumberFormat(locale, { notation: notation , compactDisplay: "short" }).format(count);
|
return new Intl.NumberFormat(locale, { notation: notation , compactDisplay: "short" }).format(count);
|
||||||
|
}),
|
||||||
|
timeAgo: (function(ts) {
|
||||||
|
let date = Date.parse(ts);
|
||||||
|
let seconds = Math.floor((new Date() - date) / 1000);
|
||||||
|
let interval = Math.floor(seconds / 31536000);
|
||||||
|
if (interval >= 1) {
|
||||||
|
return interval + "y";
|
||||||
|
}
|
||||||
|
interval = Math.floor(seconds / 604800);
|
||||||
|
if (interval >= 1) {
|
||||||
|
return interval + "w";
|
||||||
|
}
|
||||||
|
interval = Math.floor(seconds / 86400);
|
||||||
|
if (interval >= 1) {
|
||||||
|
return interval + "d";
|
||||||
|
}
|
||||||
|
interval = Math.floor(seconds / 3600);
|
||||||
|
if (interval >= 1) {
|
||||||
|
return interval + "h";
|
||||||
|
}
|
||||||
|
interval = Math.floor(seconds / 60);
|
||||||
|
if (interval >= 1) {
|
||||||
|
return interval + "m";
|
||||||
|
}
|
||||||
|
return Math.floor(seconds) + "s";
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
filters: [
|
filters: [
|
||||||
|
|
Loading…
Reference in a new issue