66 lines
1.3 KiB
JavaScript
66 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const fs = require('fs');
|
|
|
|
process.stdin.resume();
|
|
process.stdin.setEncoding('utf-8');
|
|
|
|
let inputString = '';
|
|
let currentLine = 0;
|
|
|
|
process.stdin.on('data', function(inputStdin) {
|
|
inputString += inputStdin;
|
|
});
|
|
|
|
process.stdin.on('end', function() {
|
|
inputString = inputString.split('\n');
|
|
|
|
main();
|
|
});
|
|
|
|
process.on('SIGINT', function() {
|
|
inputString = inputString.split('\n');
|
|
|
|
main();
|
|
process.exit(0);
|
|
});
|
|
|
|
function readLine() {
|
|
return inputString[currentLine++];
|
|
}
|
|
|
|
/*
|
|
* Complete the 'timeConversion' function below.
|
|
*
|
|
* The function is expected to return a STRING.
|
|
* The function accepts STRING s as parameter.
|
|
*/
|
|
|
|
function timeConversion(s) {
|
|
s = s.trim();
|
|
let shift = 0;
|
|
if (s.endsWith('PM')) {
|
|
shift += 12;
|
|
}
|
|
s = s.substring(0, s.length - 2);
|
|
let splits = s.split(":");
|
|
let hour = Number.parseInt(splits[0]) % 12 + shift;
|
|
let minute = Number.parseInt(splits[1]);
|
|
let seconds = Number.parseInt(splits[2]);
|
|
return ("" + hour).padStart(2, "0")
|
|
+ ":" + ("" + minute).padStart(2, "0")
|
|
+ ":" + ("" + seconds).padStart(2, "0");
|
|
}
|
|
|
|
function main() {
|
|
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
|
|
|
|
const s = readLine();
|
|
|
|
const result = timeConversion(s);
|
|
|
|
ws.write(result + '\n');
|
|
ws.end();
|
|
ws.close();
|
|
}
|