From 2ec20b21b89e03e02b729d546302a85bcff9c08c Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 15 Aug 2024 21:16:07 +0200 Subject: [PATCH] Update `locale` with support for meridians --- libs/js/banglejs/locale.js | 10 ++++++++-- libs/js/banglejs/locale.min.js | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libs/js/banglejs/locale.js b/libs/js/banglejs/locale.js index 351bb0d23f..afa7c8a8fa 100644 --- a/libs/js/banglejs/locale.js +++ b/libs/js/banglejs/locale.js @@ -3,12 +3,17 @@ function round(n, dp) { var p = Math.min(dp,dp - Math.floor(Math.log(n)/Math.log(10))); return n.toFixed(p); } +var _is12Hours; +function is12Hours() { + if (_is12Hours === undefined) _is12Hours = (require('Storage').readJSON('setting.json',1)||{})["12hour"]; + return _is12Hours; +} exports = { name : "system", currencySym:"£", translate : str=>str, // as-is date : (d,short) => short?("0"+d.getDate()).substr(-2)+"/"+("0"+(d.getMonth()+1)).substr(-2)+"/"+d.getFullYear():d.toString().substr(4,11).trim(), // Date to "Feb 28 2020" or "28/02/2020"(short) time : (d,short) => { // Date to "4:15.28 pm" or "15:42"(short) var h = d.getHours(), m = d.getMinutes() - if ((require('Storage').readJSON('setting.json',1)||{})["12hour"]) + if (is12Hours()) h = (h%12==0) ? 12 : h%12; // 12 hour if (short) return (" "+h).substr(-2)+":"+("0"+m).substr(-2); @@ -42,5 +47,6 @@ exports = { name : "system", currencySym:"£", distance : (m,dp) => (m<1000)?round(m,dp)+"m":round(m/1000,dp)+"km", // meters to "123m" or "1.2km" depending on size speed : (s,dp) => round(s/1.60934,dp)+"mph",// kph to "123mph" temp : (t,dp) => round(t,dp)+"'C", // degrees C to degrees C - meridian: d => (d.getHours() <= 12) ? "am":"pm" // Date to am/pm + meridian: d => is12Hours() ? (d.getHours() <= 12) ? "am":"pm" : "", // Date to am/pm + is12Hours, }; diff --git a/libs/js/banglejs/locale.min.js b/libs/js/banglejs/locale.min.js index fb927eaef0..2bb3e1bfb8 100644 --- a/libs/js/banglejs/locale.min.js +++ b/libs/js/banglejs/locale.min.js @@ -1,3 +1,3 @@ -function e(a,b){void 0===b&&(b=1);return a.toFixed(Math.min(b,b-Math.floor(Math.log(a)/Math.log(10))))}exports={name:"system",currencySym:"\xa3",translate:a=>a,date:(a,b)=>b?("0"+a.getDate()).substr(-2)+"/"+("0"+(a.getMonth()+1)).substr(-2)+"/"+a.getFullYear():a.toString().substr(4,11).trim(),time:(a,b)=>{var c=a.getHours(),d=a.getMinutes();(require("Storage").readJSON("setting.json",1)||{})["12hour"]&&(c=0==c%12?12:c%12);if(b)return(" "+c).substr(-2)+":"+("0"+d).substr(-2); -b="am";0==c?c=12:12<=c&&(12"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" ")[a.getDay()].substr(0,b?3:10),month:(a,b)=>"January February March April May June July August September October November December".split(" ")[a.getMonth()].substr(0,b?3:10),number:(a,b)=>{null==b&&(b=2);var c=a.toFixed(b),d=c|0;a=0>a?1:0;b=(""+Math.abs(c-d).toFixed(b)).substr(2,b);d= -""+d;c=d.length;for(var f="";(c-=3)>a;)f=","+d.substr(c,3)+f;return d.substr(0,c+3)+f+(b?"."+b:"")},currency:a=>{console.log("Warning: Currency information is deprecated");return"\xa3"+a.toFixed(2)},distance:(a,b)=>1E3>a?e(a,b)+"m":e(a/1E3,b)+"km",speed:(a,b)=>e(a/1.60934,b)+"mph",temp:(a,b)=>e(a,b)+"'C",meridian:a=>12>=a.getHours()?"am":"pm"} \ No newline at end of file +function e(a,b){void 0===b&&(b=1);return a.toFixed(Math.min(b,b-Math.floor(Math.log(a)/Math.log(10))))}function f(){void 0===g&&(g=(require("Storage").readJSON("setting.json",1)||{})["12hour"]);return g}var g;exports={name:"system",currencySym:"\xa3",translate:a=>a,date:(a,b)=>b?("0"+a.getDate()).substr(-2)+"/"+("0"+(a.getMonth()+1)).substr(-2)+"/"+a.getFullYear():a.toString().substr(4,11).trim(),time:(a,b)=>{var c=a.getHours(),d=a.getMinutes();f()&&(c=0==c%12?12:c%12); +if(b)return(" "+c).substr(-2)+":"+("0"+d).substr(-2);b="am";0==c?c=12:12<=c&&(12"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" ")[a.getDay()].substr(0,b?3:10),month:(a,b)=>"January February March April May June July August September October November December".split(" ")[a.getMonth()].substr(0,b?3:10),number:(a,b)=>{null==b&&(b=2);var c=a.toFixed(b),d=c|0;a= +0>a?1:0;b=(""+Math.abs(c-d).toFixed(b)).substr(2,b);d=""+d;c=d.length;for(var h="";(c-=3)>a;)h=","+d.substr(c,3)+h;return d.substr(0,c+3)+h+(b?"."+b:"")},currency:a=>{console.log("Warning: Currency information is deprecated");return"\xa3"+a.toFixed(2)},distance:(a,b)=>1E3>a?e(a,b)+"m":e(a/1E3,b)+"km",speed:(a,b)=>e(a/1.60934,b)+"mph",temp:(a,b)=>e(a,b)+"'C",meridian:a=>f()?12>=a.getHours()?"am":"pm":"",is12Hours:f} \ No newline at end of file