mirror of
https://github.com/MichMich/MagicMirror.git
synced 2026-04-23 22:37:01 +00:00
32 lines
648 B
JavaScript
32 lines
648 B
JavaScript
|
|
/**
|
||
|
|
* 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");
|
||
|
|
};
|
||
|
|
|
||
|
|
if (typeof module !== "undefined") module.exports = {
|
||
|
|
formatTime
|
||
|
|
};
|