diff --git a/apps/calendar/ChangeLog b/apps/calendar/ChangeLog index 27e1e2517..c7902e263 100644 --- a/apps/calendar/ChangeLog +++ b/apps/calendar/ChangeLog @@ -13,3 +13,4 @@ 0.12: Mark dated events on a day 0.13: Switch to swipe left/right for month and up/down for year selection Display events for current month on touch +0.14: Add support for holidays diff --git a/apps/calendar/calendar.js b/apps/calendar/calendar.js index ffe3084e6..92e3428ba 100644 --- a/apps/calendar/calendar.js +++ b/apps/calendar/calendar.js @@ -36,7 +36,12 @@ const events = (require("Storage").readJSON("sched.json",1) || []).filter(a => a date.setHours(time.h); date.setMinutes(time.m); date.setSeconds(time.s); - return {date: date, msg: a.msg}; + return {date: date, msg: a.msg, type: "e"}; +}); +// add holidays +(require("Storage").readJSON("calendar.holiday.json",1) || []).forEach(h => { + const date = new Date(h.date); + events.push({date: date, msg: h.name, type: "h"}); }); events.sort((a,b) => a.date - b.date); @@ -167,6 +172,27 @@ function drawCalendar(date) { const y1 = y * rowH + headerH + rowH; const x2 = x * colW + colW; const y2 = y * rowH + headerH + rowH + rowH; + + if (eventsThisMonth.length > 0) { + // Display events for this day + eventsThisMonth.forEach((ev, idx) => { + if (sameDay(ev.date, curDay)) { + if (ev.type === "e") { // alarm/event + const hour = ev.date.getHours() + ev.date.getMinutes()/60.0; + const slice = hour/24*(eventsPerDay-1); // slice 0 for 0:00 up to eventsPerDay for 23:59 + const height = (y2-2) - (y1+2); // height of a cell + const sliceHeight = height/eventsPerDay; + const ystart = (y1+2) + slice*sliceHeight; + g.setColor(bgEvent).fillRect(x1+1, ystart, x2-2, ystart+sliceHeight); + } else if (ev.type === "h") { // holiday + g.setColor(bgColorWeekend).fillRect(x1+1, y1+1, x2-1, y2-1); + } + + eventsThisMonth.splice(idx, 1); // this event is no longer needed + } + }); + } + if (isToday) { g.setColor(red); g.drawRect(x1, y1, x2, y2); @@ -178,23 +204,6 @@ function drawCalendar(date) { ); } - if (eventsThisMonth.length > 0) { - // Display events for this day - g.setColor(bgEvent); - eventsThisMonth.forEach((ev, idx) => { - if (sameDay(ev.date, curDay)) { - const hour = ev.date.getHours() + ev.date.getMinutes()/60.0; - const slice = hour/24*(eventsPerDay-1); // slice 0 for 0:00 up to eventsPerDay for 23:59 - const height = (y2-2) - (y1+2); // height of a cell - const sliceHeight = height/eventsPerDay; - const ystart = (y1+2) + slice*sliceHeight; - g.fillRect(x1+1, ystart, x2-2, ystart+sliceHeight); - - eventsThisMonth.splice(idx, 1); // this event is no longer needed - } - }); - } - require("Font8x12").add(Graphics); g.setFont("8x12", fontSize); g.setColor(day < 50 ? fgOtherMonth : fgSameMonth); @@ -236,7 +245,7 @@ function setUI() { const menu = events.filter(ev => ev.date.getFullYear() === date.getFullYear() && ev.date.getMonth() === date.getMonth()).map(e => { const dateStr = require("locale").date(e.date, 1); const timeStr = require("locale").time(e.date, 1); - return { title: `${dateStr} ${timeStr}` + (e.msg ? " " + e.msg : "") }; + return { title: `${dateStr} ${e.type === "e" ? timeStr : ""}` + (e.msg ? " " + e.msg : "") }; }); if (menu.length === 0) { menu.push({title: /*LANG*/"No events"}); diff --git a/apps/calendar/metadata.json b/apps/calendar/metadata.json index 87599e3f4..bf5c67b09 100644 --- a/apps/calendar/metadata.json +++ b/apps/calendar/metadata.json @@ -1,7 +1,7 @@ { "id": "calendar", "name": "Calendar", - "version": "0.13", + "version": "0.14", "description": "Simple calendar", "icon": "calendar.png", "screenshots": [{"url":"screenshot_calendar.png"}],