webmetrik/basics.js

65 lines
1.5 KiB
JavaScript
Raw Normal View History

2024-01-13 15:42:39 +00:00
const fs = require("fs")
const path = require("path")
2024-01-13 16:17:31 +00:00
var metricsPathFile = "./metrics.json"
2024-01-13 15:42:39 +00:00
module.exports.getDate = function (formated) {
var date = new Date()
// [Date Format] - Format de la date
var gmonth = date.getMonth() + 1
var gday = date.getDate()
var gHour = date.getHours()
var gMinute = date.getMinutes()
var gSecondes = date.getSeconds()
if(date.getMonth() + 1 < 10) {
gmonth = "0" + (date.getMonth() + 1)
}
if(date.getDate() + 1 <= 10) {
gday = "0" + date.getDate()
}
if(date.getHours() + 1 <= 10) {
gHour = "0" + date.getHours()
}
if(date.getMinutes() + 1 <= 10) {
gMinute = "0" + date.getMinutes()
}
if(date.getSeconds() + 1 <= 10) {
gSecondes = "0" + date.getSeconds()
}
if(!formated) {
return gday + "/" + gmonth + " - " + gHour + "h" + "-" + gMinute + "m" + "-" + gSecondes + "s"
} else {
return date.getFullYear() + "-" + gmonth + "-" + gday + "-" + gHour + "h" + "-" + gMinute + "m" + "-" + gSecondes + "s"
}
}
2024-01-13 16:10:12 +00:00
module.exports.setMetricsFile = (path) => {
metricsPathFile = path
}
2024-01-13 15:42:39 +00:00
module.exports.getMetricsFile = () => {
2024-01-13 16:17:31 +00:00
if(!fs.existsSync(metricsPathFile)) {
2024-01-13 16:10:12 +00:00
fs.writeFileSync(metricsPathFile, JSON.stringify([], null, 2))
2024-01-13 15:42:39 +00:00
} else {
2024-01-13 16:10:12 +00:00
return JSON.parse(fs.readFileSync(metricsPathFile))
2024-01-13 15:42:39 +00:00
}
}
module.exports.saveMetricsFile = (data) => {
2024-01-13 16:10:12 +00:00
fs.writeFileSync(metricsPathFile, JSON.stringify(data, null, 2))
2024-01-13 15:42:39 +00:00
}