Only return meridian for 12-hour clocks

pull/3535/head
Anton 2024-08-15 17:13:58 +02:00
parent 84aabfade4
commit 10b2e9e8dd
1 changed files with 7 additions and 4 deletions

View File

@ -204,11 +204,14 @@ function round(n, dp) {
var p = Math.max(0,Math.min(dp,dp - Math.floor(Math.log(n)/Math.log(10))));
return n.toFixed(p);
}
var is12;
var _is12Hours;
function is12Hours() {
if (_is12Hours === undefined) _is12Hours = ${isLocal ? "false" : `(require('Storage').readJSON('setting.json', 1) || {})["12hour"]`};
return _is12Hours;
}
function getHours(d) {
var h = d.getHours();
if (is12 === undefined) is12 = ${isLocal ? "false" : `(require('Storage').readJSON('setting.json', 1) || {})["12hour"]`};
if (!is12) return ('0' + h).slice(-2);
if (!is12Hours()) return ('0' + h).slice(-2);
return ((h % 12 == 0) ? 12 : h % 12).toString();
}
exports = {
@ -237,7 +240,7 @@ exports = {
translate: s => ${locale.trans?`{var t=${js(locale.trans)};s=''+s;return t[s]||t[s.toLowerCase()]||s;}`:`s`},
date: (d,short) => short ? \`${dateS}\` : \`${dateN}\`,
time: (d,short) => short ? \`${timeS}\` : \`${timeN}\`,
meridian: d => d.getHours() < 12 ? ${js(locale.ampm[0])}:${js(locale.ampm[1])},
meridian: d => is12Hours() ? d.getHours() < 12 ? ${js(locale.ampm[0])}:${js(locale.ampm[1])} : "",
};
`.trim()
};