From d6e189945e6467e87cb4e0d53bf1227bc793a5d2 Mon Sep 17 00:00:00 2001 From: Bernhard Date: Fri, 2 Aug 2024 13:11:12 +0200 Subject: [PATCH] fix(measuretime): make sure to draw correct time number on overlapping-day hours --- apps/measuretime/measuretime.app.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/measuretime/measuretime.app.js b/apps/measuretime/measuretime.app.js index 97b56c710..49f5f2835 100644 --- a/apps/measuretime/measuretime.app.js +++ b/apps/measuretime/measuretime.app.js @@ -78,6 +78,19 @@ return lineEndFull - 5; }; + let drawHourString = function(hour, yLines) { + var hourForDrawing = 0; + if (hour < 0) { + // a negative hour => (+ and - = -) + hourForDrawing = 24 + hour; + } else if (hour >= 24) { + hourForDrawing = hour - 24; + } else { + hourForDrawing = hour; + } + g.drawString(hourForDrawing, hourStringXOffset(hourForDrawing), yLines, true); + }; + let drawTime = function () { g.clear(); var d = new Date(); @@ -101,12 +114,12 @@ switch (yTopLines - 88 + mins) { case -60: lineEnd = lineEndFull; - g.drawString(d.getHours()-1, hourStringXOffset(d.getHours()-1), yTopLines, true); + drawHourString(d.getHours() - 1, yTopLines); break; case 0: case 60: lineEnd = lineEndFull; - g.drawString(d.getHours(), hourStringXOffset(d.getHours()), yTopLines, true); + drawHourString(d.getHours(), yTopLines); break; case 45: case -45: @@ -136,11 +149,11 @@ case 0: case 60: lineEnd = lineEndFull; - g.drawString(d.getHours() + 1, hourStringXOffset(d.getHours()+1), yBottomLines, true); + drawHourString(d.getHours() + 1, yBottomLines);; break; case 120: lineEnd = lineEndFull; - g.drawString(d.getHours() + 2, hourStringXOffset(d.getHours()+2), yBottomLines, true); + drawHourString(d.getHours() + 2, yBottomLines); break; case 15: case 75: