mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 15:26:58 +01:00
added silverbullets, added gettimeout command
This commit is contained in:
17
bot/lib/dateManager.ts
Normal file
17
bot/lib/dateManager.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export function buildTimeString(time1: number, time2: number) {
|
||||
const diff = Math.abs(time1 - time2);
|
||||
const timeobj = {
|
||||
day: Math.floor(diff / (1000 * 60 * 60 * 24)),
|
||||
hour: Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),
|
||||
minute: Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)),
|
||||
second: Math.floor((diff % (1000 * 60)) / 1000)
|
||||
};
|
||||
const stringarray: string[] = [];
|
||||
for (const [unit, value] of Object.entries(timeobj)) {
|
||||
if (value === 0) continue;
|
||||
if (unit === 'second' && timeobj.day > 0) continue;
|
||||
stringarray.push(`${value} ${unit}${value === 1 ? '' : 's'}`);
|
||||
};
|
||||
const last = stringarray.pop();
|
||||
return stringarray.length === 0 ? last : stringarray.join(', ') + " and " + last;
|
||||
};
|
||||
Reference in New Issue
Block a user