Skip to content

Commit

Permalink
Improving multiday events parsing
Browse files Browse the repository at this point in the history
Fixes issue #69
  • Loading branch information
anufrievroman committed Nov 28, 2023
1 parent 7529268 commit f363ccc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion calcure/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ def __init__(self, user_events, use_persian_calendar):
temp_month = event.month + rep*(event.frequency == Frequency.MONTHLY)
temp_day = event.day + rep*(event.frequency == Frequency.DAILY) + 7*rep*(event.frequency == Frequency.WEEKLY)
year, month, day = self.calculate_recurring_events(temp_year, temp_month, temp_day, event.frequency)
self.add_item(UserRepeatedEvent(event.item_id, year, month, day, event.name, event.status, event.privacy))
self.add_item(UserRepeatedEvent(event.item_id, year, month, day, event.name, event.status,
event.privacy, event.calendar_number))

def calculate_recurring_events(self, year, month, day, frequency):
"""Calculate the date of recurring events so that they occur in the next month or year"""
Expand Down
11 changes: 9 additions & 2 deletions calcure/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ def parse_event(self, component, index, calendar_number):

# Parameters of the event from ics file, if they exist:
name = str(component.get('summary', ''))
all_day = component.get('dtstart').params.get('VALUE') == 'DATE' if component.get('dtstart') else False
dt = None
try:
dt = component.get('dtstart').dt
Expand All @@ -421,14 +420,22 @@ def parse_event(self, component, index, calendar_number):
if hasattr(dt_end, "tzinfo"):
dt_end = dt_end.astimezone(self.local_timezone)

dt_difference = dt_end.date() - dt.date()
# Depending on the date type, difference is calculated differently:
try:
dt_difference = dt_end.date() - dt.date()
except:
dt_difference = dt_end - dt

if dt_difference.days > 0:
repetition = dt_difference.days + 1
frequency = Frequency.DAILY

except AttributeError:
logging.error("Failed to parse event %s on %s.", name, dt)
pass

# Add start time to non-all-day events:
all_day = component.get('dtstart').params.get('VALUE') == 'DATE' if component.get('dtstart') else False
if not all_day:
hour = dt.hour if dt else 0
minute = dt.minute if dt else 0
Expand Down

0 comments on commit f363ccc

Please sign in to comment.