Add comments to the framework & included modules #16

Merged
tgpholly merged 9 commits from add-comments into master 2020-01-04 15:18:13 +00:00
Showing only changes of commit c25c8d75d8 - Show all commits

View file

@ -13,6 +13,7 @@ if (!fs.existsSync(__dirname + BASE_PATH)) {
fs.mkdirSync(__dirname + BASE_PATH); fs.mkdirSync(__dirname + BASE_PATH);
console.log(`[consoleHelper] Made consoleHelper module folder`); console.log(`[consoleHelper] Made consoleHelper module folder`);
} }
// Creates the consoleHelper config file
if (!fs.existsSync(__dirname + BASE_PATH + "/config.json")) { if (!fs.existsSync(__dirname + BASE_PATH + "/config.json")) {
fs.writeFileSync(__dirname + BASE_PATH + "/config.json", JSON.stringify({"24hour":true})); fs.writeFileSync(__dirname + BASE_PATH + "/config.json", JSON.stringify({"24hour":true}));
console.log(`[consoleHelper] Made consoleHelper config file`); console.log(`[consoleHelper] Made consoleHelper config file`);
@ -35,20 +36,26 @@ module.exports = {
getTime24:function() { getTime24:function() {
const time = new Date(); const time = new Date();
// Check if the user wants 24 hour or 12 hour time
if (config["24hour"]) { if (config["24hour"]) {
// User wants 24 hour time, leave it as it is.
return `${correctValue(time.getHours())}:${correctValue(time.getMinutes())}:${correctValue(time.getSeconds())}`; return `${correctValue(time.getHours())}:${correctValue(time.getMinutes())}:${correctValue(time.getSeconds())}`;
} else { } else {
// User wants 12 hour time, process it for that.
return this.t2412(`${correctValue(time.getHours())}:${correctValue(time.getMinutes())}:${correctValue(time.getSeconds())}`); return this.t2412(`${correctValue(time.getHours())}:${correctValue(time.getMinutes())}:${correctValue(time.getSeconds())}`);
} }
}, },
t2412:function(inp) { t2412:function(inp) {
// Check what time it is, AM or PM.
if (parseInt(inp.split(":")[0]) > 11) { if (parseInt(inp.split(":")[0]) > 11) {
// It's over 11 so it's PM
const i = inp.split(":"); const i = inp.split(":");
let i1 = parseInt(i[0]) - 12; let i1 = parseInt(i[0]) - 12;
if (i1 == 0) i1 = 12; if (i1 == 0) i1 = 12;
return i1 + ":" + i[1] + " PM"; return i1 + ":" + i[1] + " PM";
} else { } else {
// It's lower than 12 so it's AM
const i = inp.split(":"); const i = inp.split(":");
let i1 = parseInt(i[0]); let i1 = parseInt(i[0]);
if (i1 == 0) i1 = 12; if (i1 == 0) i1 = 12;
@ -59,6 +66,7 @@ module.exports = {
module.exports.MOD_FUNC = MODULE_FUNCTION; module.exports.MOD_FUNC = MODULE_FUNCTION;
// Date returns numbers without a 0 in front of them of course so this adds them.
function correctValue(i) { function correctValue(i) {
if (i < 10) { if (i < 10) {
return "0"+i; return "0"+i;