largeclock: Support 12 hour time
parent
30864632a6
commit
86bb7da352
|
|
@ -1605,7 +1605,7 @@
|
|||
"id": "largeclock",
|
||||
"name": "Large Clock",
|
||||
"icon": "largeclock.png",
|
||||
"version": "0.04",
|
||||
"version": "0.05",
|
||||
"description": "A readable and informational digital watch, with date, seconds and moon phase",
|
||||
"readme": "README.md",
|
||||
"tags": "clock",
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@
|
|||
0.02: fix 3/4 moon orientation
|
||||
0.03: Change `largeclock.json` to 'data' file to allow settings to be preserved
|
||||
0.04: Adjust layout to account for new vector font
|
||||
0.05: Add support for 12 hour time
|
||||
|
|
@ -4,9 +4,11 @@ let interval;
|
|||
let lastMoonPhase;
|
||||
let lastMinutes;
|
||||
|
||||
const is12Hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"];
|
||||
|
||||
const moonR = 12;
|
||||
const moonX = 215;
|
||||
const moonY = 50;
|
||||
const moonY = is12Hour ? 90 : 50;
|
||||
|
||||
const settings = require("Storage").readJSON("largeclock.json", 1)||{};
|
||||
const BTN1app = settings.BTN1 || "";
|
||||
|
|
@ -118,15 +120,23 @@ function drawMoon(d) {
|
|||
|
||||
function drawTime(d) {
|
||||
const da = d.toString().split(" ");
|
||||
const time = da[4].substr(0, 5).split(":");
|
||||
const time = da[4].split(":");
|
||||
const dow = da[0];
|
||||
const month = da[1];
|
||||
const day = da[2];
|
||||
const year = da[3];
|
||||
const hours = time[0];
|
||||
const hours = is12Hour ? ("0" + (((d.getHours() + 11) % 12) + 1)).substr(-2) : time[0];
|
||||
const meridian = d.getHours() < 12 ? "AM" : "PM";
|
||||
const minutes = time[1];
|
||||
const seconds = d.getSeconds();
|
||||
const seconds = time[2];
|
||||
if (minutes != lastMinutes) {
|
||||
if (is12Hour) {
|
||||
g.setFont("Vector", 18);
|
||||
g.setColor(1, 1, 1);
|
||||
g.setFontAlign(0, -1);
|
||||
g.clearRect(195, 34, 240, 44);
|
||||
g.drawString(meridian, 217, 34);
|
||||
}
|
||||
g.clearRect(0, 24, moonX - moonR - 10, 239);
|
||||
g.setColor(1, 1, 1);
|
||||
g.setFontAlign(-1, -1);
|
||||
|
|
@ -137,7 +147,7 @@ function drawTime(d) {
|
|||
g.setFont("Vector", 20);
|
||||
g.setRotation(3);
|
||||
g.drawString(`${dow} ${day} ${month}`, 50, 10, true);
|
||||
g.drawString(year, 75, 205, true);
|
||||
g.drawString(year, is12Hour ? 46 : 75, 205, true);
|
||||
lastMinutes = minutes;
|
||||
}
|
||||
g.setRotation(0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue