Skip to content

Commit

Permalink
Add offset note to description
Browse files Browse the repository at this point in the history
  • Loading branch information
RealOrangeOne committed Apr 17, 2024
1 parent 513aecd commit c1338b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions calmerge/calendars.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def create_offset_calendar_events(
f" ({abs(days)} days {'after' if days > 0 else 'before'})"
)

if "DESCRIPTION" in day_component:
day_component["DESCRIPTION"] += (
f"\n\nNote: This event has been offset {days} days."
)

new_components.append(day_component)

for component in new_components:
Expand Down
17 changes: 15 additions & 2 deletions tests/test_calendar_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,21 @@ async def test_offset_calendar_matches(client: TestClient) -> None:
len(offset_calendar.walk("VEVENT")) == len(original_calendar.walk("VEVENT")) * 2
)

offset_events = [
event
for event in offset_calendar.walk("VEVENT")
if event["SUMMARY"].endswith("(365 days after)")
]

assert len(offset_events) == len(original_calendar.walk("VEVENT"))

original_events_by_summary = {
event["SUMMARY"]: event for event in original_calendar.walk("VEVENT")
}

for offset_event in offset_calendar.walk("VEVENT"):
for offset_event in offset_events:
assert offset_event["SUMMARY"].endswith(" (365 days after)")

original_event = original_events_by_summary[
offset_event["SUMMARY"].removesuffix(" (365 days after)")
]
Expand All @@ -76,4 +86,7 @@ async def test_offset_calendar_matches(client: TestClient) -> None:
original_event["dtstamp"].dt + timedelta(days=365)
)

assert offset_event["description"] == original_event["description"]
assert offset_event["description"].startswith(original_event["description"])
assert offset_event["description"].endswith(
"Note: This event has been offset 365 days."
)

0 comments on commit c1338b2

Please sign in to comment.