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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,28 @@ events:
In this meeting we will ...
```

## Timezones

The event timezone can be specified in three ways (in reverse order of precedence):

1. Using the `timezone: ...` field, as shown above under "Syntax".
2. Adding it to an individual event:

```yaml
- summary: My event
timezone: US/Pacific
```

3. By specifying a timezone in the event start time:

```
2021-09-21 15:00:00 +07:00
```

Valid timezones are listed at https://datetime.app/iana-timezones

If no timezone is set, we default to UTC.

## Contributing

Contributions are welcomed! This project is still in active development
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ ignore = [
"ARG001", # Unused function argument
"PT012", # `pytest.raises()` block
"PLW0129", # Asserting on a non-empty string literal will always pass
"SIM108", # Use ternary operator instead of `if`-`else`-block
]

[tool.pytest.ini_options]
Expand Down
16 changes: 16 additions & 0 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,19 @@ def test_events_with_multiple_timezones():
assert events[1].begin.tzname() in ("UTC", "Coordinated Universal Time")
assert events[2].begin.tzname() == "PDT"
assert events[3].begin.tzname() == "PST"


def test_events_without_timezone():
f = io.BytesIO(b"""
name: Default Timezone
events:
- summary: Meeting A
begin: 2025-09-02 17:00:00
duration: { minutes: 60 }
- summary: Meeting B
begin: 2025-12-01 09:00:00
end: 2025-12-01 10:00:00
""")
events, _ = files_to_events([f])
assert events[0].begin.tzname() in ("UTC", "Coordinated Universal Time")
assert events[1].begin.tzname() in ("UTC", "Coordinated Universal Time")
6 changes: 4 additions & 2 deletions yaml2ics.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def gettz(tzname: str) -> datetime.tzinfo:
# This function can be used to add a list of e.g. exception dates (EXDATE) or
# recurrence dates (RDATE) to a reoccurring event
def add_recurrence_property(
Copy link
Member

Choose a reason for hiding this comment

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

I think we make TZ required for now; this is for internal use anyway.

event: ics.Event, property_name, dates: map, tz: datetime.tzinfo = None
event: ics.Event, property_name, dates: map, tz: datetime.tzinfo = dateutil.tz.UTC
):
event.extra.append(
ics.ContentLine(
name=property_name,
params={"TZID": [str(ics.Timezone.from_tzinfo(tz))]} if tz else None,
params={"TZID": [str(ics.Timezone.from_tzinfo(tz))]},
value=",".join(dates),
)
)
Expand All @@ -68,6 +68,8 @@ def event_from_yaml(event_yaml: dict, tz: datetime.tzinfo = None) -> ics.Event:
repeat = d.pop("repeat", None)
ics_custom = d.pop("ics", None)

if tz is None:
tz = dateutil.tz.UTC
if "timezone" in d:
tzname = d.pop("timezone")
tz = gettz(tzname)
Expand Down
Loading