Well, I thought I had it with this
let timeStr = “blank”;
let consoleOut = console.log(watch.hour12 ${watch.hour12});
let hour12 = !!consoleOut;
if (hour12 === true) {
timeStr = “12”;
} else {
timeStr = “24”;
}
That shows 24 in the emulator window
If I change if (hour12 === true) to if (hour12 === false) I get 12 in the emulator window.
Since I can’t try switching to 12-hour in the emulator, the checkbox is still stuck on 24-hour, I tried running it on my phone using DevConnect. There I do not get this behaviour.
import Poco from “commodetto/Poco”;
const render = new Poco(screen);
// Fonts
const timeFont = new render.Font(“Bitham-Bold”, 42);
const dateFont = new render.Font(“Gothic-Bold”, 24);
// Colors
const black = render.makeColor(0, 0, 0);
const white = render.makeColor(255, 255, 255);
// Day and month names for date formatting
const DAYS = [“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”];
const MONTHS = [“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”,
“Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Dec”];
function log(data){
console.log(data);
return data;
}
function draw(event) {
const now = event.date;
render.begin();
render.fillRectangle(black, 0, 0, render.width, render.height);
// Format time as HH:MM
const hours = String(now.getHours()).padStart(2, "0");
const minutes = String(now.getMinutes()).padStart(2, "0");
// const timeStr = ${hours}:${minutes};
let timeStr = “blank”;
let consoleOut = console.log(watch.hour12 ${watch.hour12});
let hour12 = !!consoleOut;
if (hour12 === false) {
timeStr = “12”;
} else {
timeStr = “24”;
}
// Center the time vertically (shifted up slightly to make room for date)
let width = render.getTextWidth(timeStr, timeFont);
render.drawText(timeStr, timeFont, white,
(render.width - width) / 2,
(render.height / 2) - timeFont.height + 5);
// Format date as "Mon Jan 01"
const dayName = DAYS[now.getDay()];
const monthName = MONTHS[now.getMonth()];
const dateStr = `${dayName} ${monthName} ${String(now.getDate()).padStart(2, "0")}`;
// Draw date below the time
width = render.getTextWidth(dateStr, dateFont);
render.drawText(dateStr, dateFont, white,
(render.width - width) / 2,
(render.height / 2) + 10);
render.end();
}
// Update every minute (fires immediately when registered)
watch.addEventListener(“minutechange”, draw);