diff options
author | WlodekM <[email protected]> | 2024-12-01 12:32:53 +0200 |
---|---|---|
committer | WlodekM <[email protected]> | 2024-12-01 12:32:53 +0200 |
commit | 84ebada2cc3a7f6f094d249ceae0df49f66e55bc (patch) | |
tree | 470b9623677e0144d023ae99e6bb564fa89043ba /lib/t.js | |
parent | 18b3dc1aeaeac7114f68ea0eab9ad59c7991b0ae (diff) |
wip user popup
Diffstat (limited to 'lib/t.js')
-rw-r--r-- | lib/t.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/t.js b/lib/t.js new file mode 100644 index 0000000..77af51f --- /dev/null +++ b/lib/t.js @@ -0,0 +1,26 @@ +export function timeSince(date) { + const seconds = Math.floor((new Date() - date) / 1000); + + const interval = seconds / 31536000; + + if (interval > 1) { + return Math.floor(interval) + " years"; + } + interval = seconds / 2592000; + if (interval > 1) { + return Math.floor(interval) + " months"; + } + interval = seconds / 86400; + if (interval > 1) { + return Math.floor(interval) + " days"; + } + interval = seconds / 3600; + if (interval > 1) { + return Math.floor(interval) + " hours"; + } + interval = seconds / 60; + if (interval > 1) { + return Math.floor(interval) + " minutes"; + } + return Math.floor(seconds) + " seconds"; +} \ No newline at end of file |