summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Brox <tobias@redpill-linpro.com>2020-06-06 20:52:43 +0200
committerTobias Brox <tobias@redpill-linpro.com>2020-06-06 20:52:43 +0200
commit2f1fdbb13175535e4b52f75616cbaf11a81181d3 (patch)
tree84dfe0c40232dee3b7edd809b8d2d6a9ee7dd59a
parentbb6d7221ce061e040176c903678a9bfe41247b6f (diff)
downloadcalendar-cli-2f1fdbb13175535e4b52f75616cbaf11a81181d3.zip
partial fix for https://github.com/tobixen/calendar-cli/issues/11 - fix TZ when adding events. (agenda is still fubarred when caldav server yields timezone information)
-rwxr-xr-xcalendar-cli.py4
-rwxr-xr-xtests/tests.sh29
2 files changed, 30 insertions, 3 deletions
diff --git a/calendar-cli.py b/calendar-cli.py
index 9ad4bc4..be4a609 100755
--- a/calendar-cli.py
+++ b/calendar-cli.py
@@ -324,7 +324,6 @@ def calendar_add(caldav_conn, args):
cal.add('prodid', '-//{author_short}//{product}//{language}'.format(author_short=__author_short__, product=__product__, language=args.language))
cal.add('version', '2.0')
event = Event()
- ## TODO: timezone
## read timestamps from arguments
event_spec = args.event_time.split('+')
if len(event_spec)>3:
@@ -343,7 +342,7 @@ def calendar_add(caldav_conn, args):
event_duration = '1h'
## TODO: error handling
event_duration_secs = int(event_duration[:-1]) * time_units[event_duration[-1:]]
- dtstart = dateutil.parser.parse(event_spec[0])
+ dtstart = dateutil.parser.parse(event_spec[0], ignoretz=True)
if (args.whole_day or
(event_duration_secs % (60*60*24) == 0 and
dtstart.time() == time_(0,0))):
@@ -357,6 +356,7 @@ def calendar_add(caldav_conn, args):
event.add('dtstart', _date(dtstart.date()))
event.add('dtend', _date(dtend.date()))
else:
+ dtstart = _tz(args.timezone).localize(dtstart)
event.add('dtstart', dtstart)
## TODO: handle duration and end-time as options. default 3600s by now.
event.add('dtend', dtstart + timedelta(0,event_duration_secs))
diff --git a/tests/tests.sh b/tests/tests.sh
index 9718709..4ab51e8 100755
--- a/tests/tests.sh
+++ b/tests/tests.sh
@@ -94,8 +94,35 @@ echo "$output" | grep -q "20101013" || error "could not find the date"
echo "$output" | grep -q "20101013T" && error "a supposed whole day event was found to be with the time of day"
echo "OK: found the event"
+echo "## cleanup, delete it"
+calendar_cli calendar delete --event-uid=$uid
+
+echo "## testing timezone support"
+echo "## Create a UTC event"
+calendar_cli --timezone='UTC' calendar add '2010-10-09 12:00:00+2h' 'testevent with a UTC timezone'
+uid=$(echo $output | perl -ne '/uid=(.*)$/ && print $1')
+[ -n "$uid" ] || error "got no UID back"
+
+echo "## fetching the UTC-event, as ical data"
+calendar_cli --icalendar calendar agenda --from-time=2010-10-08 --agenda-days=3
+echo "$output" | grep -q "20101009T120000Z" || error "failed to find the UTC timestamp. Perhaps the server is yielding timezone data for the UTC timezone? In that case, the assert in the test code should be adjusted"
+
+echo "## cleanup, delete it"
+calendar_cli calendar delete --event-uid=$uid
+
+echo "## Create an event with a somewhat remote time zone, west of UTC"
+calendar_cli --timezone='Brazil/DeNoronha' calendar add '2010-10-09 12:00:00+2h' 'testevent with a time zone west of UTC'
+uid=$(echo $output | perl -ne '/uid=(.*)$/ && print $1')
+[ -n "$uid" ] || error "got no UID back"
+
+echo "## fetching the UTC-event, as ical data"
+calendar_cli --icalendar calendar agenda --from-time=2010-10-08 --agenda-days=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 "## cleanup, delete it"
+calendar_cli calendar delete --event-uid=$uid
-## TODOS / TASK LISTS
+echo "## TODOS / TASK LISTS"
echo "## Attempting to add a task with category 'scripttest'"
calendar_cli todo add --set-categories scripttest "edit this task"