calendar - fix off-by-one-error on next year

The calendar jumps from 2022 to 2024 between December and January,
and this seems to fix it

Signed-off-by: James Taylor <jt-git@nti.me.uk>
master
James Taylor 2022-10-16 19:37:20 +01:00
parent 351ac60233
commit c5f5efff26
3 changed files with 5 additions and 5 deletions

View File

@ -9,3 +9,4 @@
read start of week from system settings read start of week from system settings
0.09: Fix scope of let variables 0.09: Fix scope of let variables
0.10: Use default Bangle formatter for booleans 0.10: Use default Bangle formatter for booleans
0.11: Fix off-by-one-error on next year

View File

@ -226,15 +226,14 @@ drawCalendar(date);
clearWatch(); clearWatch();
Bangle.on("touch", area => { Bangle.on("touch", area => {
const month = date.getMonth(); const month = date.getMonth();
let prevMonth;
if (area == 1) { if (area == 1) {
let prevMonth = month > 0 ? month - 1 : 11; let prevMonth = month > 0 ? month - 1 : 11;
if (prevMonth === 11) date.setFullYear(date.getFullYear() - 1); if (prevMonth === 11) date.setFullYear(date.getFullYear() - 1);
date.setMonth(prevMonth); date.setMonth(prevMonth);
} else { } else {
let prevMonth = month < 11 ? month + 1 : 0; let nextMonth = month < 11 ? month + 1 : 0;
if (prevMonth === 0) date.setFullYear(date.getFullYear() + 1); if (nextMonth === 0) date.setFullYear(date.getFullYear() + 1);
date.setMonth(month + 1); date.setMonth(nextMonth);
} }
drawCalendar(date); drawCalendar(date);
}); });

View File

@ -1,7 +1,7 @@
{ {
"id": "calendar", "id": "calendar",
"name": "Calendar", "name": "Calendar",
"version": "0.10", "version": "0.11",
"description": "Simple calendar", "description": "Simple calendar",
"icon": "calendar.png", "icon": "calendar.png",
"screenshots": [{"url":"screenshot_calendar.png"}], "screenshots": [{"url":"screenshot_calendar.png"}],