From 10b2e9e8dd06e74110bc51013d6a32e849c0f20e Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 15 Aug 2024 17:13:58 +0200 Subject: [PATCH 1/2] Only return meridian for 12-hour clocks --- apps/locale/locale.html | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/locale/locale.html b/apps/locale/locale.html index 8ec818aae..4e1f954d8 100644 --- a/apps/locale/locale.html +++ b/apps/locale/locale.html @@ -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() }; From 332d3ca3362ab51f3f800758da8bdf6bb79a1d2f Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 15 Aug 2024 17:14:17 +0200 Subject: [PATCH 2/2] Add `is12Hour` function to locale --- apps/locale/locale.html | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/locale/locale.html b/apps/locale/locale.html index 4e1f954d8..ae8cd8204 100644 --- a/apps/locale/locale.html +++ b/apps/locale/locale.html @@ -241,6 +241,7 @@ exports = { date: (d,short) => short ? \`${dateS}\` : \`${dateN}\`, time: (d,short) => short ? \`${timeS}\` : \`${timeN}\`, meridian: d => is12Hours() ? d.getHours() < 12 ? ${js(locale.ampm[0])}:${js(locale.ampm[1])} : "", + is12Hours, }; `.trim() };