Add time parser for timer command
* Fix grammar * Fix countdown off by 4 seconds
This commit is contained in:
parent
5f4a0056d7
commit
e676730f0c
2 changed files with 22 additions and 3 deletions
19
util/parseTime.js
Normal file
19
util/parseTime.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
module.exports = function(time){
|
||||
let timeInMilliseconds = parseInt(time.slice(0, time.length - 1))
|
||||
let letter = time.slice(time.length - 1)
|
||||
if(!isNaN(letter)) return parseInt(time) * 60000
|
||||
switch (letter.toUpperCase()) {
|
||||
case "H":
|
||||
timeInMilliseconds = timeInMilliseconds * 3600000; // 3 600 000
|
||||
break;
|
||||
case "M":
|
||||
timeInMilliseconds = timeInMilliseconds * 60000; // 60 000
|
||||
break;
|
||||
case "S":
|
||||
timeInMilliseconds = timeInMilliseconds * 1000; // 1 000
|
||||
break;
|
||||
default:
|
||||
timeInMilliseconds = -1;
|
||||
}
|
||||
return timeInMilliseconds;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue