humanise time

This commit is contained in:
Erik 2022-01-15 02:24:11 +02:00
parent 59e27d98b7
commit a8973c8a64
No known key found for this signature in database
GPG Key ID: FEFF4B220DDF5589

View File

@ -1,9 +1,26 @@
const moment = require('moment'); const moment = require('moment');
const humaniseDuration = require('humanize-duration');
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
const { Util: DiscordUtil } = require('discord.js'); 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); const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
class Util { class Util {
@ -151,6 +168,10 @@ class Util {
.replace(/-/gu, '\\x2d'); .replace(/-/gu, '\\x2d');
} }
static humanise(seconds, relative = false) {
return humaniser(seconds * 1000, { largest: 2 }) + (relative ? ' ago' : '');
}
/** /**
* Convert seconds to a human readable string representation * Convert seconds to a human readable string representation
* @param {int} seconds * @param {int} seconds