Skip to content

Commit

Permalink
Merge pull request #2540 from atjn/meridian-fix
Browse files Browse the repository at this point in the history
Update `locale` with support for meridians
  • Loading branch information
gfwilliams committed Aug 27, 2024
2 parents e3df9e9 + 2ec20b2 commit 4b413bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 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,
};
6 changes: 3 additions & 3 deletions libs/js/banglejs/locale.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4b413bf

Please sign in to comment.