-
Notifications
You must be signed in to change notification settings - Fork 0
/
rTime.js
37 lines (32 loc) · 1.2 KB
/
rTime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const ms = require("ms")
const calculateMilliseconds = args => {
let bantimeArray = args.split(",");
let bantime = 0;
bantimeArray.forEach(t => {
let milsecs = ms(t);
bantime = bantime + milsecs;
});
return bantime;
}
const rTime = args => {
let mis = calculateMilliseconds(args);
const days = Math.floor(mis / (1000 * 60 * 60 * 24));
const hours = Math.floor((mis % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((mis % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((mis % (1000 * 60)) / 1000);
let lDays = days + " days";
if (days === 1) lDays = days + " day";
let lHours = hours + " hours";
if (hours === 1) lHours = hours + " hour";
let lMinutes = minutes + " minutes";
if (minutes === 1) lMinutes = minutes + " minute";
let lSeconds = seconds + " seconds";
if (seconds === 1) lSeconds = seconds + " second";
let time = "";
if (days) time = `${time} ${lDays}`;
if (hours) time = `${time} ${lHours}`;
if (minutes) time = `${time} ${lMinutes}`;
if (seconds) time = `${time} ${lSeconds}`;
return time.slice(1);
}
module.exports = { rTime, calculateMilliseconds };