Files
MagicMirror/defaultmodules/utils.js
T

32 lines
648 B
JavaScript
Raw Normal View History

2023-07-01 21:17:31 +02:00
/**
* Format the time according to the config
* @param {object} config The config of the module
* @param {object} time time to format
* @returns {string} The formatted time string
*/
const formatTime = (config, time) => {
let date = moment(time);
if (config.timezone) {
date = date.tz(config.timezone);
}
if (config.timeFormat !== 24) {
if (config.showPeriod) {
if (config.showPeriodUpper) {
return date.format("h:mm A");
} else {
return date.format("h:mm a");
}
} else {
return date.format("h:mm");
}
}
return date.format("HH:mm");
};
2024-01-01 15:38:08 +01:00
if (typeof module !== "undefined") module.exports = {
formatTime
};