forked from Galactic/galactic-bot
humanise time
This commit is contained in:
parent
59e27d98b7
commit
a8973c8a64
21
src/Util.js
21
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
|
||||
|
Loading…
Reference in New Issue
Block a user