Skip to content

Commit 9f9fe7c

Browse files
committed
[multitimer] add support for 12h format; update changelog + metadata
1 parent bce2e55 commit 9f9fe7c

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

apps/multitimer/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
0.10: Handle missing alarm data, e.g. when our reset is fired from
1212
non-multitimer alarms
1313
0.11: Preserve setUI removal callbacks, e.g. those of showMenu
14+
0.12: Fix displaying timers that go to next day; add 12h locale support

apps/multitimer/app.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function getTimeRemaining(alarm) {
2323
if (rem === undefined) {
2424
// fallback: compute time difference
2525
const now = getCurrentTime();
26-
if (alarm.t > now) {
26+
if (alarm.t >= now) {
2727
rem = alarm.t - now;
2828
} else {
2929
rem = MS_PER_DAY - (now - alarm.t);
@@ -32,6 +32,16 @@ function getTimeRemaining(alarm) {
3232
return rem;
3333
}
3434

35+
function formatAlarmTime(t) {
36+
// t is milliseconds since local midnight
37+
const dt = decodeTime(t);
38+
// Use locale.time so formatting respects 12h/24h user settings
39+
const d = new Date(1999, 1, 1, dt.hrs, dt.mins, 0);
40+
const timeStr = require("locale").time(d, 1);
41+
const mer = require("locale").meridian(d, 1);
42+
return timeStr + mer;
43+
}
44+
3545
function decodeTime(t) {
3646
let hrs = 0 | Math.floor(t / 3600000);
3747
let mins = 0 | Math.floor(t / 60000 % 60);
@@ -561,8 +571,7 @@ function drawAlarms() {
561571
.setColor(g.theme.fg).setFont("6x8:2").setFontAlign(0,0).drawString("< Swipe >",r.x+(r.w/2),r.y+(r.h/2));
562572
}
563573
else if (idx > 0 && idx < alarms.length+1){
564-
const str = formatTime(alarms[idx-1].t);
565-
drawMenuItem(str.slice(0, -3));
574+
drawMenuItem(formatAlarmTime(alarms[idx-1].t));
566575
}
567576
},
568577
select : (idx) => {
@@ -646,6 +655,11 @@ function editAlarm(idx, a) {
646655
},
647656
"Hours": {
648657
value: t.hrs, min: 0, max: 23, wrap: true,
658+
format: v => {
659+
// Show 12h or 24h based on locale settings
660+
const mer = require("locale").meridian(new Date(1999,1,1,v,0,0), 1);
661+
return (!mer) ? v : (v%12||12) + mer;
662+
},
649663
onchange: v => {
650664
t.hrs = v;
651665
a.t = encodeTime(t);

apps/multitimer/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "multitimer",
33
"name": "Multi Timer",
4-
"version": "0.11",
4+
"version": "0.12",
55
"description": "Set timers and chronographs (stopwatches) and watch them count down in real time. Pause, create, edit, and delete timers and chronos, and add custom labels/messages. Also sets alarms.",
66
"icon": "app.png",
77
"screenshots": [

0 commit comments

Comments
 (0)