Created
September 9, 2017 14:56
-
-
Save ResearcherOne/92a73c12ea066a6e2fc16471616fa1bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readline = require('readline'); | |
const roundTo = require('round-to'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
function printHelpMessage(){ | |
console.log("<<--COMMANDS-->>"); | |
console.log("<time_command_output>"); | |
console.log("exit"); | |
} | |
function getLineInput(callback){ | |
rl.question('>>>', callback); | |
} | |
function parseUserInput(answer) { | |
var tokenizedAnswer = answer.split("m"); | |
var minutes = tokenizedAnswer[0]; | |
if(tokenizedAnswer[0] == "exit") process.exit(0); | |
if(tokenizedAnswer[1]) { | |
var tokenizedAnswerSeconds = tokenizedAnswer[1].split("s"); | |
var seconds = tokenizedAnswerSeconds[0]; | |
if(tokenizedAnswerSeconds[0]) { | |
console.log("mins: "+minutes); | |
const minutesToSeconds = parseInt(minutes)*60; | |
console.log("Minutes in seconds:"+minutesToSeconds); | |
console.log("seconds: "+seconds); | |
const roundedSeconds = roundTo(parseFloat(seconds), 1); | |
console.log("rounded seconds: "+roundedSeconds); | |
console.log("Total Seconds: "+(minutesToSeconds+roundedSeconds)); | |
} else { | |
console.log("invalid input"); | |
} | |
} else { | |
console.log("invalid input"); | |
} | |
getLineInput(parseUserInput); | |
} | |
printHelpMessage(); | |
getLineInput(parseUserInput); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment