Merge pull request #3526 from prefectAtEarth/master

measuretime: fix hour calculation fix on day-end overlapping hours
pull/3532/head
Rob Pilling 2024-08-02 18:39:22 +01:00 committed by GitHub
commit 8c262abb87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 5 deletions

View File

@ -1,2 +1,3 @@
0.1: Initial release
0.2: Draw line for 3d effect, fix number alignment
0.3: Fix day-end overflowing hour calculation

View File

@ -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:

View File

@ -1,7 +1,7 @@
{
"id": "measuretime",
"name": "Measure Time",
"version": "0.2",
"version": "0.3",
"description": "Measure Time in a fancy way.",
"icon": "measuretime_icon.png",
"screenshots": [