From 22fbce4758f1cf265732c67f76c62e4733eb2a34 Mon Sep 17 00:00:00 2001 From: Ace Date: Wed, 11 Dec 2019 23:23:52 +0100 Subject: [PATCH 1/3] Set event times correctly Instead of setting the timezone-aware (local) time of each event in every module, the icalendar module does it by default now. As a result, when importing events in any other module, the time will be correct. --- Inky-Calendar/modules/inkycal_icalendar.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Inky-Calendar/modules/inkycal_icalendar.py b/Inky-Calendar/modules/inkycal_icalendar.py index 978e6a9..a7bff5b 100644 --- a/Inky-Calendar/modules/inkycal_icalendar.py +++ b/Inky-Calendar/modules/inkycal_icalendar.py @@ -38,6 +38,11 @@ def fetch_events(): for events in upcoming_events: if events.all_day and events.duration.days > 1: events.end = events.end.replace(days=-2) + + if not events.all_day: + events.begin = events.begin.to(get_tz()) + events.end = events.end.to(get_tz()) + """ The list upcoming_events should not be modified. If you need the data from this one, copy the list or the contents to another one.""" From 94dd38f88079dfbf5c88031f0bb8c6759d94dff1 Mon Sep 17 00:00:00 2001 From: Ace Date: Wed, 11 Dec 2019 23:24:52 +0100 Subject: [PATCH 2/3] Code cleanup Removed non-required conversion of event time as the icalendar module now handles this task --- Inky-Calendar/modules/inkycal_calendar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Inky-Calendar/modules/inkycal_calendar.py b/Inky-Calendar/modules/inkycal_calendar.py index 20a5feb..99f7718 100644 --- a/Inky-Calendar/modules/inkycal_calendar.py +++ b/Inky-Calendar/modules/inkycal_calendar.py @@ -116,9 +116,9 @@ def main(): if show_events == True: """Filter events which begin before the end of this month""" upcoming_events = fetch_events() + calendar_events = [events for events in upcoming_events if - events.begin.to(get_tz()) < month_end and - events.begin.month == now.month] + events.begin < month_end and events.begin.month == now.month] """Find days with events in the current month""" days_with_events = [] From 8618e0046b760f68ec98f281453c164ec8621cce Mon Sep 17 00:00:00 2001 From: Ace Date: Wed, 11 Dec 2019 23:28:58 +0100 Subject: [PATCH 3/3] Bugfix for event-times Cleaned up code converting event times to local timezone, since the icalendar module handles this task by default now. Fixed a problem where events would not show up correctly on the agenda module. Changed the used font for better readability. --- Inky-Calendar/modules/inkycal_agenda.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Inky-Calendar/modules/inkycal_agenda.py b/Inky-Calendar/modules/inkycal_agenda.py index f1c74a0..04a9773 100644 --- a/Inky-Calendar/modules/inkycal_agenda.py +++ b/Inky-Calendar/modules/inkycal_agenda.py @@ -20,7 +20,7 @@ border_top = int(middle_section_height * 0.02) border_left = int(middle_section_width * 0.02) """Choose font optimised for the agenda section""" -font = ImageFont.truetype(NotoSans+'.ttf', fontsize) +font = ImageFont.truetype(NotoSans+'Medium.ttf', fontsize) line_height = int(font.getsize('hg')[1] * 1.2) + 1 line_width = int(middle_section_width - (border_left*2)) @@ -44,17 +44,18 @@ def main(): clear_image('middle_section') print('Agenda module: Generating image...', end = '') - now = arrow.now() + now = arrow.now(get_tz()) + today_start = arrow.get(now.year, now.month, now.day) """Create a list of dictionaries containing dates of the next days""" - agenda_events = [{'date':now.replace(days=+_), + agenda_events = [{'date':today_start.replace(days=+_), 'date_str': now.replace(days=+_).format('ddd D MMM',locale=language), 'type':'date'} for _ in range(max_lines)] """Copy the list from the icalendar module with some conditions""" upcoming_events = fetch_events() filtered_events = [events for events in upcoming_events if - events.end.to(get_tz()) > now] + events.end > now] """Set print_events_to True to print all events in this month""" if print_events == True and filtered_events: @@ -68,10 +69,6 @@ def main(): and create a ready-to-display list for the agenda view""" for events in filtered_events: if not events.all_day: - - events.end = events.end.to(get_tz()) - events.begin = events.begin.to(get_tz()) - agenda_events.append({'date': events.begin, 'time': events.begin.format( 'HH:mm' if hours == '24' else 'hh:mm a'), 'name':str(events.name), 'type':'timed_event'})