Merge pull request #7 from tgpethan/12-hour-time

Add 12 hour time option for console output
This commit is contained in:
Ethan Stubbs 2020-01-02 23:00:34 +00:00 committed by GitHub
commit 6e4d00eae8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 4 deletions

3
.gitignore vendored
View file

@ -3,4 +3,5 @@
node_modules/ node_modules/
package-lock.json package-lock.json
config/config.json config/config.json
utils/ utils/
modules/consoleHelper/config.json

View file

@ -1,10 +1,24 @@
const chalk = require("chalk"); const chalk = require("chalk"),
fs = require("fs");
// Defines the function of this module // Defines the function of this module
const MODULE_FUNCTION = "handle_console", const MODULE_FUNCTION = "handle_console",
// Base path for module folder creation and navigation // Base path for module folder creation and navigation
BASE_PATH = null; BASE_PATH = "/consoleHelper";
// Only ran on startup so using sync functions is fine
// Makes the folders for files of the module
if (!fs.existsSync(__dirname + BASE_PATH)) {
fs.mkdirSync(__dirname + BASE_PATH);
console.log(`[consoleHelper] Made consoleHelper module folder`);
}
if (!fs.existsSync(__dirname + BASE_PATH + "/config.json")) {
fs.writeFileSync(__dirname + BASE_PATH + "/config.json", JSON.stringify({"24hour":true}));
console.log(`[consoleHelper] Made consoleHelper config file`);
}
const config = require(__dirname + BASE_PATH + "/config.json");
module.exports = { module.exports = {
printInfo:function(emoji, s) { printInfo:function(emoji, s) {
@ -21,7 +35,25 @@ module.exports = {
getTime24:function() { getTime24:function() {
const time = new Date(); const time = new Date();
return `${correctValue(time.getHours())}:${correctValue(time.getMinutes())}:${correctValue(time.getSeconds())}` if (config["24hour"]) {
return `${correctValue(time.getHours())}:${correctValue(time.getMinutes())}:${correctValue(time.getSeconds())}`;
} else {
return this.t2412(`${correctValue(time.getHours())}:${correctValue(time.getMinutes())}:${correctValue(time.getSeconds())}`);
}
},
t2412:function(inp) {
if (parseInt(inp.split(":")[0]) > 11) {
const i = inp.split(":");
let i1 = parseInt(i[0]) - 12;
if (i1 == 0) i1 = 12;
return i1 + ":" + i[1] + " PM";
} else {
const i = inp.split(":");
let i1 = parseInt(i[0]);
if (i1 == 0) i1 = 12;
return i1 + ":" + i[1] + " AM";
}
} }
} }