Skip to content

Commit 54113fb

Browse files
committed
Add a timezone test
1 parent a0f31dc commit 54113fb

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

tests/test_calendar.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
import io
23
import textwrap
34

@@ -28,3 +29,39 @@ def test_calendar_event():
2829
assert cal_str.startswith('BEGIN:VCALENDAR')
2930
assert 'SUMMARY:Earth Day' in cal_str
3031
assert cal_str.endswith('END:VCALENDAR')
32+
33+
def test_calendar_default_timezone():
34+
cal = files_to_calendar(
35+
[io.StringIO(textwrap.dedent(
36+
'''
37+
meta:
38+
tz: Europe/Helsinki
39+
40+
events:
41+
- summary: New year's day
42+
begin: 2022-01-01 00:00:00
43+
duration: {hours: 1}
44+
45+
- summary: February 1
46+
begin: 2022-02-01 00:00:00 +02:00
47+
duration: {hours: 1}
48+
'''
49+
))]
50+
)
51+
cal_str = cal.serialize()
52+
assert cal_str.startswith('BEGIN:VCALENDAR')
53+
assert 'SUMMARY:New year' in cal_str
54+
# It is possible that the ics-py TZID string changes, but hopefully this
55+
# substring is fairly safe to test against.
56+
assert 'Europe/Helsinki:20220101T000000' in cal_str
57+
# Second event: explicit UTC offset specified.
58+
assert '"UTC+02:00":20220201T000000' in cal_str
59+
assert cal_str.endswith('END:VCALENDAR')
60+
61+
# Test again by normalizing to UTC. Helsinki is two hours ahead, so the
62+
# times should be 22:00:00.
63+
cal.normalize(datetime.timezone.utc)
64+
cal_norm_str = cal.serialize()
65+
# 1 Feb midnight
66+
assert 'DTSTART:20211231T220000Z' # 1 jan
67+
assert 'DTSTART:20220131T220000Z' # 1 feb

0 commit comments

Comments
 (0)