Skip to content

Commit

Permalink
fixed if there is no year in a birthday entry
Browse files Browse the repository at this point in the history
  • Loading branch information
philippspinnler committed Oct 11, 2024
1 parent efa5c29 commit 22517c2
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions app/plugins/ical.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,29 @@ def handle_birthdays(events):

# Extract the year part from the name_part
parts = name_part.split()
year_part = parts[-1]

# Remove the year from the name_part to clean the summary
name = " ".join(parts[:-1])
if len(parts) == 1:
# If there's only one part, assume it's the name
name = parts[0]
age = None
else:
year_part = parts[-1]

try:
year = int(year_part)
# Remove the year from the name_part to clean the summary
name = " ".join(parts[:-1])

# If it's a 2-digit year, assume it's in the 1900s (e.g., 85 -> 1985)
if year < 100:
year += 1900
try:
year = int(year_part)

# Calculate the age based on the current year
current_year = datetime.now().year
age = current_year - year
except ValueError:
age = None
# If it's a 2-digit year, assume it's in the 1900s (e.g., 85 -> 1985)
if year < 100:
year += 1900

# Calculate the age based on the current year
current_year = datetime.now().year
age = current_year - year
except ValueError:
age = None
else:
birthday = False

Expand Down

0 comments on commit 22517c2

Please sign in to comment.