Skip to content
Open
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,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
10 changes: 7 additions & 3 deletions yaml2ics.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,20 @@ def utcnow():
# 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(
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),
)
)


def event_from_yaml(event_yaml: dict, tz: datetime.tzinfo = None) -> ics.Event:
def event_from_yaml(
event_yaml: dict, tz: datetime.tzinfo = dateutil.tz.UTC
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 either change the default, or change the handling below, but not both.

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel it makes most sense to change the default here, and then let the event timezone overwrite. Or it maybe cleaner to drop the tz kwarg altogether and rely only on the yaml and have a conditional?

    if "timezone" in d:
        tz = gettz(d.pop("timezone"))
    else:
        tz = dateutil.tz.UTC

) -> ics.Event:
d = event_yaml
repeat = d.pop("repeat", None)
ics_custom = d.pop("ics", None)
Expand Down Expand Up @@ -171,6 +173,8 @@ def files_to_events(files: list) -> (ics.Calendar, str):
tz = calendar_yaml.get("timezone", None)
if tz is not None:
tz = gettz(tz)
else:
tz = dateutil.tz.UTC
if "include" in calendar_yaml:
included_events, _name = files_to_events(
os.path.join(os.path.dirname(f), newfile)
Expand Down
Loading