Skip to content

Commit

Permalink
Update locale with support for meridians
Browse files Browse the repository at this point in the history
  • Loading branch information
atjn committed Aug 15, 2024
1 parent ff487e0 commit 9af1331
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libs/js/banglejs/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
};

0 comments on commit 9af1331

Please sign in to comment.