diff options
author | Tobias Brox <tobias@redpill-linpro.com> | 2020-05-14 16:30:01 +0200 |
---|---|---|
committer | Tobias Brox <tobias@redpill-linpro.com> | 2020-05-14 16:30:01 +0200 |
commit | 054398d15d0bfc4483c30569bae83f72f1d6065a (patch) | |
tree | 3cad77e99a9636095c94283b1eb008c438ee8e21 | |
parent | 863bf6f280d6d714c46deb55c93e99106083e8cc (diff) | |
download | calendar-cli-054398d15d0bfc4483c30569bae83f72f1d6065a.zip |
a minor timezone cleanup (potential messup) + fix for recurring events, fixing https://github.com/tobixen/calendar-cli/issues/52
-rwxr-xr-x | calendar-cli.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/calendar-cli.py b/calendar-cli.py index b08eb19..ba34a46 100755 --- a/calendar-cli.py +++ b/calendar-cli.py @@ -93,7 +93,7 @@ def _force_datetime(t, args): if type(t) == date: t = datetime(t.year, t.month, t.day) if t.tzinfo is None: - return t.replace(tzinfo=_tz(args)) + return t.replace(tzinfo=_tz(args.timezone)) return t def _now(): @@ -102,9 +102,9 @@ def _now(): """ return datetime.utcnow().replace(tzinfo=pytz.utc) -def _tz(args): - if args.timezone: - return pytz.timezone(args.timezone) +def _tz(timezone=None): + if timezone: + return pytz.timezone(timezone) else: return tzlocal.get_localzone() @@ -477,22 +477,18 @@ def calendar_agenda(caldav_conn, args): for ical in events_: print(ical.data).encode('utf-8').strip() else: - ## flatten. A recurring event may be a list of events. - ## jeez ... zimbra and DaviCal does completely different things here - ## (wonder if we ought to push some logic over to the caldav library) for event_cal in events_: - if hasattr(event_cal.instance, 'vcalendar'): - events__ = event_cal.instance.components() - elif hasattr(event_cal.instance, 'vevent'): - events__ = [ event_cal.instance.vevent ] + if hasattr(event_cal.instance, 'vtimezone'): + tzinfo = event_cal.instance.vtimezone else: - raise Exception("Panic") + tzinfo = args.timezone + events__ = event_cal.instance.components() for event in events__: dtstart = event.dtstart.value if hasattr(event, 'dtstart') else _now() if not isinstance(dtstart, datetime): dtstart = datetime(dtstart.year, dtstart.month, dtstart.day) if not dtstart.tzinfo: - dtstart = _tz(args).localize(dtstart) + dtstart = _tz(args.timezone).localize(dtstart) events.append({'dtstart': dtstart, 'instance': event}) ## changed to use the "key"-parameter at 2019-09-18, as needed for python3. ## this will probably cause regression on sufficiently old versions of python |