diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-06-01 03:30:39 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-06-01 03:30:39 +0200 |
| commit | 964ac7009e6db5a06233bdc07fa63778eebf2db7 (patch) | |
| tree | 960ceb019514f960a6597b9b282baf4d5cd77607 /app/client/util.js | |
| parent | dd31a7b9a3af167808b04ffe2af3a66af8b17c33 (diff) | |
async commands!!
Diffstat (limited to 'app/client/util.js')
| -rw-r--r-- | app/client/util.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/client/util.js b/app/client/util.js index 04eb9c6..2ba6d3f 100644 --- a/app/client/util.js +++ b/app/client/util.js @@ -124,4 +124,25 @@ export function hush_null (n, unit, no_bold) { return ["new", s] } } +export function get_age (t) { + var age = Math.abs(+Date.now() - new Date(t))/1000 + var r = Math.floor + var m + if (age < 5) { return "now" } + if (age < 60) { return r(age) + "s" } + age /= 60 + if (age < 60) { return r(age) + "m" } + m = r(age % 60) + age /= 60 + if (m > 0 && age < 2) { return r(age) + "h" + m + "m" } + if (age < 24) { return r(age) + "h" } + age /= 24 + if (age < 7) { return r(age) + "d" } + age /= 7 + if (age < 12) { return r(age) + "w" } + age /= 4 + if (age < 12) { return r(age) + "m" } + age /= 12 + return r(age) + "y" +} export function courtesy_s (n, s) { return n == 1 ? "" : (s || "s") } |
