discord_bot/util/timer/parseTime.js
SileNce5k ed77c2aaf1
All checks were successful
CI / CI (push) Successful in 1m24s
Allow dates to be used in timer command
And some general cleanup of a couple of functions.
2025-05-17 11:15:05 +02:00

28 lines
693 B
JavaScript

module.exports = function(time, currentUnixTime){
let timeInSeconds = parseFloat(time)
const letterCount = time.length - timeInSeconds.toString().length;
const letter = time.slice(time.length - letterCount);
switch (letter.toUpperCase()) {
case "H":
timeInSeconds = timeInSeconds * 3_600;
break;
case "M":
timeInSeconds = timeInSeconds * 60;
break;
case "S":
break;
case "D":
timeInSeconds = timeInSeconds * 86_400;
break;
case "TS": // Unix timestamp
case "T":
timeInSeconds = timeInSeconds - currentUnixTime;
break;
case "W":
timeInSeconds = timeInSeconds * 86_400 * 7;
break;
default:
timeInSeconds = NaN;
}
return timeInSeconds;
}