Skip to content

Commit 0ac4c51

Browse files
authored
Merge pull request #3695 from tnyeanderson/agenda-fix
fix(agenda): all day event offsets, locale display
2 parents bc5fb81 + bcf88c3 commit 0ac4c51

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

apps/agenda/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
0.13: Show day of the week in date
1616
0.14: Fixed "Today" and "Yesterday" wrongly displayed for allDay events on some time zones
1717
0.15: Minor code improvements
18+
0.16: Correct date for all day events in negative timezones, improve locale display

apps/agenda/agenda.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ var settings = require("Storage").readJSON("agenda.settings.json",true)||{};
3030

3131
CALENDAR=CALENDAR.sort((a,b)=>a.timestamp - b.timestamp);
3232

33-
function getDate(timestamp) {
34-
return new Date(timestamp*1000);
33+
function getDate(timestamp, allDay) {
34+
// All day events are always in UTC and always start at 00:00:00, so we
35+
// need to "undo" the timezone offsetting to make sure that the day is
36+
// correct.
37+
var offset = allDay ? new Date().getTimezoneOffset() * 60 : 0
38+
return new Date((timestamp+offset)*1000);
3539
}
40+
3641
function formatDay(date) {
37-
let formattedDate = Locale.dow(date,1) + " " + Locale.date(date).replace(/\d\d\d\d/,"");
42+
let formattedDate = Locale.dow(date,1) + " " + Locale.date(date).replace(/,*\s*\d\d\d\d/,"");
3843
if (!settings.useToday) {
3944
return formattedDate;
4045
}
@@ -57,8 +62,9 @@ function formatDateLong(date, includeDay, allDay) {
5762
}
5863
return shortTime;
5964
}
65+
6066
function formatDateShort(date, allDay) {
61-
return formatDay(date)+(allDay?"":Locale.time(date,1)+Locale.meridian(date));
67+
return formatDay(date)+(allDay?"":" "+Locale.time(date,1)+Locale.meridian(date));
6268
}
6369

6470
var lines = [];
@@ -69,16 +75,19 @@ function showEvent(ev) {
6975
//var lines = [];
7076
if (ev.title) lines = g.wrapString(ev.title, g.getWidth()-10);
7177
var titleCnt = lines.length;
72-
var start = getDate(ev.timestamp);
73-
var end = getDate((+ev.timestamp) + (+ev.durationInSeconds));
78+
var start = getDate(ev.timestamp, ev.allDay);
79+
// All day events end at the midnight boundary of the following day. Here, we
80+
// subtract one second for all day events so the days display correctly.
81+
const allDayEndCorrection = ev.allDay ? 1 : 0;
82+
var end = getDate((+ev.timestamp) + (+ev.durationInSeconds) - allDayEndCorrection, ev.allDay);
7483
var includeDay = true;
7584
if (titleCnt) lines.push(""); // add blank line after title
7685
if(start.getDay() == end.getDay() && start.getMonth() == end.getMonth())
7786
includeDay = false;
78-
if(includeDay && ev.allDay) {
79-
//single day all day (average to avoid getting previous day)
87+
if(!includeDay && ev.allDay) {
88+
//single day all day
8089
lines = lines.concat(
81-
g.wrapString(formatDateLong(new Date((start+end)/2), includeDay, ev.allDay), g.getWidth()-10));
90+
g.wrapString(formatDateLong(start, includeDay, ev.allDay), g.getWidth()-10));
8291
} else if(includeDay || ev.allDay) {
8392
lines = lines.concat(
8493
/*LANG*/"Start"+":",
@@ -137,7 +146,7 @@ function showList() {
137146
if (!ev) return;
138147
var isPast = false;
139148
var x = r.x+2, title = ev.title;
140-
var body = formatDateShort(getDate(ev.timestamp),ev.allDay)+"\n"+(ev.location?ev.location:/*LANG*/"No location");
149+
var body = formatDateShort(getDate(ev.timestamp, ev.allDay),ev.allDay)+"\n"+(ev.location?ev.location:/*LANG*/"No location");
141150
if(settings.pastEvents) isPast = ev.timestamp + ev.durationInSeconds < (new Date())/1000;
142151
if (title) g.setFontAlign(-1,-1).setFont(fontBig)
143152
.setColor(isPast ? "#888" : g.theme.fg).drawString(title, x+4,r.y+2);

apps/agenda/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "agenda",
33
"name": "Agenda",
4-
"version": "0.15",
4+
"version": "0.16",
55
"description": "Simple agenda",
66
"icon": "agenda.png",
77
"screenshots": [{"url":"screenshot_agenda_overview.png"}, {"url":"screenshot_agenda_event1.png"}, {"url":"screenshot_agenda_event2.png"}],

0 commit comments

Comments
 (0)