Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.1.0
rev: 22.3.0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
Expand Down
5 changes: 5 additions & 0 deletions example/test_calendar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ events:
location: |
Office 224, Monolith Bldg, Office Block C

- summary: 15-minute meeting with timezone
timezone: America/New_York # symbolic timezone offset
begin: 2021-09-23 15:00:00
end: 2021-09-23 15:30:00

- summary: Half-an-hour meeting
begin: 2021-09-23 15:00:00 -07:00 # explicit timezone offset
end: 2021-09-23 15:30:00 -07:00 # explicit timezone offset
Expand Down
35 changes: 35 additions & 0 deletions tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,41 @@ def test_calendar_default_timezone():
assert "DTSTART:20220131T220000Z" # 1 feb


def test_calendar_event_different_timezone():
# This test is just like the one above, but with the timezone definition
# locations changed.
cal = files_to_calendar(
[
iowrap(
"""
timezone: America/New_York

events:
- summary: New year's day
timezone: Europe/Helsinki
begin: 2022-01-01 00:00:00
duration: {hours: 1}
"""
)
]
)
cal_str = cal.serialize()
assert cal_str.startswith("BEGIN:VCALENDAR")
assert "SUMMARY:New year" in cal_str
# It is possible that the ics-py TZID string changes, but hopefully this
# substring is fairly safe to test against.
assert "Europe/Helsinki:20220101T000000" in cal_str

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth asserting that New_York is not in there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I should have thought of that. Added.

assert "America/New_York" not in cal_str

# Test again by normalizing to UTC. Helsinki is two hours ahead, so the
# times should be 22:00:00.
cal.normalize(datetime.timezone.utc)
cal_norm_str = cal.serialize() # noqa: F841
# 1 Feb midnight
assert "DTSTART:20211231T220000Z" # 1 jan
assert "DTSTART:20220131T220000Z" # 1 feb


def test_calendar_name():
cal = files_to_calendar(
[
Expand Down
2 changes: 2 additions & 0 deletions yaml2ics.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
def event_from_yaml(event_yaml: dict, tz: tzinfo = None) -> ics.Event:
d = event_yaml
repeat = d.pop("repeat", None)
if "timezone" in d:
tz = gettz(d.pop("timezone"))

# Strip all string values, since they often end on `\n`
for key in d:
Expand Down