diff --git a/src/Util.js b/src/Util.js index 5764239..ebf9b9e 100644 --- a/src/Util.js +++ b/src/Util.js @@ -1,9 +1,26 @@ const moment = require('moment'); +const humaniseDuration = require('humanize-duration'); const path = require('path'); const fs = require('fs'); const fetch = require('node-fetch'); const { Util: DiscordUtil } = require('discord.js'); +const humaniser = humaniseDuration.humanizer({ + language: 'short', + languages: { + short: { + y: () => "y", + mo: () => "mo", + w: () => "w", + d: () => "d", + h: () => "h", + m: () => "m", + s: () => "s", + ms: () => "ms" + } + } +}); + const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k); class Util { @@ -151,6 +168,10 @@ class Util { .replace(/-/gu, '\\x2d'); } + static humanise(seconds, relative = false) { + return humaniser(seconds * 1000, { largest: 2 }) + (relative ? ' ago' : ''); + } + /** * Convert seconds to a human readable string representation * @param {int} seconds