summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Brox <tobias@redpill-linpro.com>2020-06-06 22:44:03 +0200
committerTobias Brox <tobias@redpill-linpro.com>2020-06-06 22:44:03 +0200
commitc45cf2b250d3c1b0989a3352d1d5b534ee61119a (patch)
tree9f05d4bea04e08282af61c1b94a319d2d912ffad
parent82f0151e57dbbcfc6fb4844e3508777715feb6bb (diff)
downloadcalendar-cli-c45cf2b250d3c1b0989a3352d1d5b534ee61119a.zip
more work on proper timestamp localization/conversion in agenda. Resolves https://github.com/tobixen/calendar-cli/issues/11
-rwxr-xr-xcalendar-cli.py15
-rwxr-xr-xtests/tests.sh12
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