|
| 1 | +import datetime |
1 | 2 | import io |
2 | 3 | import textwrap |
3 | 4 |
|
@@ -28,3 +29,39 @@ def test_calendar_event(): |
28 | 29 | assert cal_str.startswith('BEGIN:VCALENDAR') |
29 | 30 | assert 'SUMMARY:Earth Day' in cal_str |
30 | 31 | 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