From f52875b064c12bef9941b9bb0749f36739eb9111 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Mon, 11 Apr 2022 20:11:16 -0700 Subject: [PATCH] Fix replies for all-day events All day events (from gmail, at least) don't contain time or timezone information. Therefore, if dtstart/dtend is a date (which has no astimezone method), don't try to change the time zone. Only copy vtimezone if it is present. --- mutt-ical.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mutt-ical.py b/mutt-ical.py index a60da0a..1979e83 100755 --- a/mutt-ical.py +++ b/mutt-ical.py @@ -63,12 +63,10 @@ def get_answer(invitation): ans.add('vevent') # just copy from invitation - for i in ["uid", "summary", "dtstart", "dtend", "organizer"]: + for i in ["uid", "summary", "dtstart", "dtend", "organizer", "vtimezone"]: if i in invitation.vevent.contents: ans.vevent.add(invitation.vevent.contents[i][0]) - ans.vtimezone = invitation.vtimezone - # new timestamp ans.vevent.add('dtstamp') ans.vevent.dtstamp.value = datetime.utcnow().replace( @@ -94,6 +92,12 @@ def openics(invitation_file): invitation = vobject.readOne(f, ignoreUnreadable=True) return invitation +def format_date(value): + if isinstance(value, datetime): + return value.astimezone(tz=None).strftime("%Y-%m-%d %H:%M %z") + else: + return value.strftime("%Y-%m-%d %H:%M %z") + def display(ical): summary = ical.vevent.contents['summary'][0].value if 'organizer' in ical.vevent.contents: @@ -128,9 +132,9 @@ def display(ical): sys.stdout.write(attendee.value.split(':')[1] + " <" + attendee.value.split(':')[1] + ">, ") #workaround for 'mailto:' in email sys.stdout.write("\n") if hasattr(ical.vevent, 'dtstart'): - print("Start:\t%s" % (ical.vevent.dtstart.value.astimezone(tz=None).strftime("%Y-%m-%d %H:%M %z"),)) + print("Start:\t%s" % (format_date(ical.vevent.dtstart.value),)) if hasattr(ical.vevent, 'dtend'): - print("End:\t%s" % (ical.vevent.dtend.value.astimezone(tz=None).strftime("%Y-%m-%d %H:%M %z"),)) + print("End:\t%s" % (format_date(ical.vevent.dtend.value),)) if locations: sys.stdout.write("Location:\t") for location in locations: