From 2f91496e57d3f2148f8212ae6e5dca2fe28f28cf Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Wed, 4 Sep 2024 01:10:59 +0200 Subject: [PATCH] Add Midnight Add README --- apps/dutchclock/README.md | 18 ++++++++++++++++++ apps/dutchclock/app.js | 28 ++++++++++++++-------------- apps/dutchclock/metadata.json | 9 +++++---- 3 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 apps/dutchclock/README.md diff --git a/apps/dutchclock/README.md b/apps/dutchclock/README.md new file mode 100644 index 000000000..167cd4a4c --- /dev/null +++ b/apps/dutchclock/README.md @@ -0,0 +1,18 @@ +# Dutch Clock +This clock shows the time, in words, the way a Dutch person would tell you what time it is. Useful when learning Dutch. + +It was inspired by my wife, who sometimes insists I tell her exactly what time it says on the watch and not just an approximation. + +## Options +- Three modes: + - exact time ("zeven voor half zes / twee voor tien") + - approximate time, rounded to the nearest 5-minute mark ("bijna vijf voor half zes / tegen tienen") (the default) + - hybrid mode, rounded when close to the quarter marks and exact otherwise ("zeven voor half zes / tegen tienen") +- Option to turn top widgets on/off (on by default) +- Option to show digital time at the bottom (off by default) +- Option to show the date at the bottom (on by default) + +## Screenshots +![](screenshotbangle1-2.png) +![](screenshotbangle2.png) +![](screenshotbangle1.png) diff --git a/apps/dutchclock/app.js b/apps/dutchclock/app.js index 90e1e3c78..9523a360c 100644 --- a/apps/dutchclock/app.js +++ b/apps/dutchclock/app.js @@ -7,8 +7,9 @@ const SCREEN_HEIGHT = g.getHeight(); const TOP_SPACING = 5; const WIDGETS_HEIGHT = 20; const DATETIME_SPACING_HEIGHT = 5; -const DATE_HEIGHT = 10; const TIME_HEIGHT = 10; +const DATE_HEIGHT = 10; +const BOTTOM_SPACING = 5; const TEXT_WIDTH = SCREEN_WIDTH - 2; @@ -84,18 +85,19 @@ function draw() { // Reset the state of the graphics library g.clear(true); + // draw the current time (4x size 7 segment) setFont(timeLines); g.setFontAlign(0,0); // align center top - g.drawString(timeLines.join("\n"), X, Y, true /*clear background*/); + g.drawString(timeLines.join("\n"), X, Y, false); if (bottomLines.length) { // draw the time and/or date, in a normal font g.setFont("6x8"); g.setFontAlign(0,1); // align center bottom // pad the date - this clears the background if the date were to change length - g.drawString(bottomLines.join('\n'), SCREEN_WIDTH/2, SCREEN_HEIGHT - 5, true /*clear background*/); + g.drawString(bottomLines.join('\n'), SCREEN_WIDTH/2, SCREEN_HEIGHT - BOTTOM_SPACING, false); } /* Show launcher when middle button pressed @@ -130,13 +132,13 @@ function getBottomLines() { } if (settings.showDate) { - lines.push(locale.date(date, 1)); + lines.push(locale.date(date)); } return lines; } - function getTimeLines(m) { +function getTimeLines(m) { switch (settings.variant) { case VARIANT_EXACT: return getExactTimeLines(m); @@ -153,6 +155,10 @@ function getBottomLines() { } function getExactTimeLines(m) { + if (m === 0) { + return ['middernacht']; + } + const hour = getHour(m); const minutes = getMinutes(hour.offset); @@ -166,15 +172,8 @@ function getExactTimeLines(m) { function getApproximateTimeLines(m) { const roundMinutes = getRoundMinutes(m); - const hour = getHour(roundMinutes.minutes); - const minutes = getMinutes(hour.offset); - - const lines = minutes.concat(hour.lines); - - if (lines.length === 1) { - lines.push('uur'); - } + const lines = getExactTimeLines(roundMinutes.minutes); return addApproximateDescription(lines, roundMinutes.offset); } @@ -222,7 +221,7 @@ function addApproximateDescription(lines, offset) { return lines; } - if (lines[1] === 'uur') { + if (lines.length === 1 || lines[1] === 'uur') { const singular = lines[0]; const plural = getPlural(singular); return { @@ -243,6 +242,7 @@ function addApproximateDescription(lines, offset) { function getPlural(h) { return { + middernacht: 'middernacht', een: 'enen', twee: 'tweeën', drie: 'drieën', diff --git a/apps/dutchclock/metadata.json b/apps/dutchclock/metadata.json index d1b352e0c..5ee68b709 100644 --- a/apps/dutchclock/metadata.json +++ b/apps/dutchclock/metadata.json @@ -3,16 +3,16 @@ "name": "Dutch Clock", "shortName":"Dutch Clock", "icon": "app.png", - "version":"0.10", + "version":"0.11", "description": "A clock that displays the time the way a Dutch person would respond when asked what time it is.", "type": "clock", "tags": "clock,dutch,text", "supports": ["BANGLEJS", "BANGLEJS2"], "allow_emulator": true, "screenshots": [ + {"url":"screenshotbangle1-2.png"}, {"url":"screenshotbangle2.png"}, - {"url":"screenshotbangle1.png"}, - {"url":"screenshotbangle1-2.png"} + {"url":"screenshotbangle1.png"} ], "storage": [ {"name":"dutchclock.app.js","url":"app.js"}, @@ -22,6 +22,7 @@ ], "data": [ {"name":"dutchclock.json"} - ] + ], + "readme":"README.md" } \ No newline at end of file