diff options
-rwxr-xr-x | calendar-cli.py | 15 | ||||
-rwxr-xr-x | tests/tests.sh | 12 |
2 files changed, 20 insertions, 7 deletions
diff --git a/calendar-cli.py b/calendar-cli.py index 4f58ce5..c032d1d 100755 --- a/calendar-cli.py +++ b/calendar-cli.py @@ -489,18 +489,23 @@ def calendar_agenda(caldav_conn, args): else: for event_cal in events_: if hasattr(event_cal.instance, 'vtimezone'): - tzinfo = event_cal.instance.vtimezone + ## i'm not sure this is useful + tzinfo = event_cal.instance.vtimezone.gettzinfo() else: - tzinfo = args.timezone + tzinfo = _tz(args.timezone) events__ = event_cal.instance.components() for event in events__: - if event.name != 'vevent': + if event.name != 'VEVENT': continue 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.timezone).localize(dtstart) + else: + if not dtstart.tzinfo: + dtstart.localize(tzinfo) + ## convert into timezone given in args: + dtstart = dtstart.astimezone(_tz(args.timezone)) + 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 diff --git a/tests/tests.sh b/tests/tests.sh index b429cfd..fa2ff3d 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -116,9 +116,17 @@ calendar_cli --timezone='Brazil/DeNoronha' calendar add '2010-10-09 12:00:00+2h' uid=$(echo $output | perl -ne '/uid=(.*)$/ && print $1') [ -n "$uid" ] || error "got no UID back" -echo "## fetching the UTC-event, as ical data" +echo "## fetching the remote time zone event, as ical data" calendar_cli --icalendar --timezone=UTC calendar agenda --from-time='2010-10-09 13:59' --agenda-mins=3 -echo "$output" | grep -q "TZID=Brazil" || error "failed to find the Brazilian timezone. perhaps the server is yielding an UTC timestamp? In that case, the assert in the test code should be adjusted." +echo "$output" | grep -q "TZID=Brazil" || error "failed to find the remote timezone. perhaps the server is yielding '1400Z' instead? In that case, the assert in the test code should be adjusted." + +echo "## fetching the remote time zone event, in UTC-time" +calendar_cli --timezone=UTC calendar agenda --from-time='2010-10-09 13:59' --agenda-mins=3 --event-template='{dtstart}' +[ "$output" == '2010-10-09 14:00 (Sat)' ] || error "expected dtstart to be 2010-10-09 14:00 (Sat)" + +echo "## fetching the remote time zone event, in CET-time (UTC+2 with DST, and October is defined as summer in Oslo, weird)" +calendar_cli --timezone=Europe/Oslo calendar agenda --from-time='2010-10-09 15:59' --agenda-mins=3 --event-template='{dtstart}' +[ "$output" == '2010-10-09 16:00 (Sat)' ] || error "expected dtstart to be 2010-10-09 15:00 (Sat)" echo "## cleanup, delete it" calendar_cli calendar delete --event-uid=$uid |