clkinfostopw: format hours/minutes/seconds

pull/2589/head
Rob Pilling 2023-01-06 22:20:38 +00:00
parent ae74346bb1
commit 7aa89220be
3 changed files with 21 additions and 1 deletions

View File

@ -0,0 +1 @@
0.01: New clkinfo!

View File

@ -13,7 +13,25 @@
redrawInterval = setInterval(() => this.emit('redraw'), 100); redrawInterval = setInterval(() => this.emit('redraw'), 100);
}; };
const duration = () => ((Date.now() - startTime) / 1000).toFixed(1); const pad2 = s => ('0' + s.toFixed(0)).slice(-2);
const duration = () => {
let seconds = (Date.now() - startTime) / 1000;
if (seconds < 60)
return seconds.toFixed(1);
let mins = seconds / 60;
seconds %= 60;
if (mins < 60)
return `${pad2(mins)}m${pad2(seconds)}s`;
let hours = mins / 60;
mins %= 60;
return `${Math.round(hours)}h${pad2(mins)}m${pad2(seconds)}s`;
};
return { return {
name: "timer", name: "timer",

View File

@ -7,6 +7,7 @@
"type": "clkinfo", "type": "clkinfo",
"tags": "clkinfo,timer", "tags": "clkinfo,timer",
"supports" : ["BANGLEJS2"], "supports" : ["BANGLEJS2"],
"allow_emulator": true,
"storage": [ "storage": [
{"name":"stopw.clkinfo.js","url":"clkinfo.js"} {"name":"stopw.clkinfo.js","url":"clkinfo.js"}
] ]