diff options
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") } |
