Skip to content

Commit

Permalink
Fix multiday event handling
Browse files Browse the repository at this point in the history
Remove debugging comments
  • Loading branch information
PhongT16 committed Nov 3, 2023
1 parent d80fd86 commit f24021e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
4 changes: 3 additions & 1 deletion IndividualCalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,15 @@ def process_individual_calendars(calendar, start_date, end_date):
filtered_events = []
for member in calendar['value']:
net_id = member['scheduleId'].split('@')[0]

try:
for event in member['scheduleItems']:
if event['status'] != EVENT_STATUS: continue

simple_events = SimpleEvent.create_event_for_individual_calendars(event, start_date, end_date, net_id)
filtered_events.extend(simple_events)

except KeyError as e:
logger.warning(f"Unable to find: " + net_id)

return filtered_events
31 changes: 26 additions & 5 deletions SimpleEvent.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from dataclasses import dataclass
from datetime import datetime
from datetime import time
from datetime import timedelta
import utils


# If a multiday event starts at 12:00 AM on a Monday and ends at 5PM on a Wednesday. Then only two events will be created:
# ALL-DAY for Monday and Tuesday, but no events for Wednesday
# If a multiday event starts at 11:00 AM on a Monday and ends at 5PM on a Wednesday. Then only three events will be created:
# ALL-DAY for Tuesday, OUT AM for Monday and OUT PM for Wednesday
configs = utils.get_configurations()
# AM_config = configs['AM_config']
# PM_config = configs['PM_config']
Expand Down Expand Up @@ -50,20 +54,37 @@ def create_event_for_individual_calendars(cls, event, start_date, end_date, net_
# Automatically All Day
dates_interval = end - start

for i in range(dates_interval.days + 1): # The plus accounts for the last day of the multiday event. Even if it's just one All-Day
add_on = 0
remaining_hours = dates_interval.seconds // 3600

if (remaining_hours!= 0):
add_on = add_on + 1

# if (start.time() >= )

midnight_start_time = time(0, 0, 0, 0)

if (start.time() != midnight_start_time and end.time() <= start.time()):
add_on = add_on + 1

for i in range(dates_interval.days + add_on): # The plus accounts for the last day of the multiday event. Even if it's just one All-Day

#new_date = start + timedelta(days=i)

# new_start and new_end are just changing the time
new_start = start + timedelta(days=i)
new_end = start + timedelta(days=i)
new_end = end + timedelta(days=i)
new_end = new_end.replace(year=new_start.year, month=new_start.month, day=new_start.day)

# Adjust the time so that we can create an accurate subject for the split up event
# Manipulating the time for the simple event here

if (i == 0):
new_end = new_end.replace(hour=23,minute=59,second=59)
elif (i == dates_interval.days):
elif (i == dates_interval.days + add_on - 1):
new_start = new_start.replace(hour=0,minute=0,second=0)
if (new_end.time() == midnight_start_time):
new_end = new_end.replace(hour=23,minute=59,second=59)
else:
new_start = new_start.replace(hour=0,minute=0,second=0)
new_end = new_end.replace(hour=23,minute=59,second=59)
Expand Down Expand Up @@ -186,7 +207,7 @@ def is_AM(start, end):
return False

if start_time < start_of_workday:
start_time= start_of_workday
start_time = start_of_workday

if end_time > start_of_lunch:
end_time = start_of_lunch
Expand Down
1 change: 1 addition & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,5 @@ def connection_error_handler(message, response, access_token):

#email_list = get_email_list('org_ici', 20)
#print(email_list)
#print(get_email_list_from_ldap('org_ici'))

0 comments on commit f24021e

Please sign in to comment.