Should now support 12 hour clocl

pull/1925/head
deirdreobyrne 2022-06-06 20:57:26 +01:00
parent e12da4cfe9
commit 7256f11f94
4 changed files with 40 additions and 3 deletions

View File

@ -1,2 +1,2 @@
0.01: Initial version
0.02: setTimeout bug fix; no leading zero on date; lightmode; cleanup
0.02: setTimeout bug fix; no leading zero on date; lightmode; 12 hour format; cleanup

View File

@ -28,13 +28,22 @@ function draw() {
w = date.getDay(); // d=1..31; w=0..6
const level = E.getBattery();
const width = level + (level/2);
var settings = Object.assign({
"12hour": false,
}, require('Storage').readJSON("bigdclock.json", true) || {});
g.reset();
g.clear();
g.setFontOpenSans();
g.setFontAlign(0, -1);
g.drawString(("0"+h).substr(-2) + ":" + ("0"+m).substr(-2), g.getWidth() / 2, 30);
if (settings["12hour"]) {
if (h > 12) h -= 12;
if (h == 0) h = 12;
g.drawString(h + ":" + ("0"+m).substr(-2), g.getWidth() / 2, 30);
} else {
g.drawString(("0"+h).substr(-2) + ":" + ("0"+m).substr(-2), g.getWidth() / 2, 30);
}
g.setFontAlign(1, -1);
g.drawString(d, g.getWidth() -6, 98);
g.setFont('Vector', 52);

View File

@ -0,0 +1,26 @@
(function(back) {
var settings = Object.assign({
"12hour": false,
}, require('Storage').readJSON("bigdclock.json", true) || {});
function set12hour(val) {
settings["12hour"]=val;
require('Storage').writeJSON("bigdclock.json", settings);
}
var mainmenu = {
"": {
"title": "BigDClock"
},
"< Back": () => back(),
"Time format": {
value: (settings["12hour"] !== undefined ? settings["12hour"] : false),
format: v => v ? "12 hr" : "24 hr",
onchange: v=> { set12hour(v) }
}
};
E.showMenu(mainmenu);
});

View File

@ -12,6 +12,8 @@
"screenshots": [ { "url":"screenshot.png" } ],
"storage": [
{"name":"bigdclock.app.js","url":"bigdclock.app.js"},
{"name":"bigdclock.settings.js","url":"bigdclock.settings.js"},
{"name":"bigdclock.img","url":"bigdclock.icon.js","evaluate":true}
]
],
"data": [{"name":"bigdclock.json"}]
}