Skip to content

Commit

Permalink
fixup! [IMP] resource_multi_week_calendar: Implement _attendance_inte…
Browse files Browse the repository at this point in the history
…rvals_batch

Signed-off-by: Carmen Bianca BAKKER <carmen@coopiteasy.be>
  • Loading branch information
carmenbianca committed Aug 30, 2024
1 parent 96c50f6 commit ebe510f
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions resource_multi_week_calendar/models/resource_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,22 @@ def get_multi_week_epoch_date(self):

@api.model
def _split_into_weeks(self, start_dt, end_dt):
# TODO: This method splits weeks on the timezone of start_dt. Maybe it
# should split weeks on the timezone of the calendar. It is not
# immediately clear to me how to implement that.
current_start = start_dt

while current_start <= end_dt:
# Calculate the end of the week (Sunday, 23:59:59)
days_until_sunday = 6 - current_start.weekday()
week_end = current_start + timedelta(days=days_until_sunday)
week_end = week_end.replace(
hour=23, minute=59, second=59, microsecond=999999
)
while current_start < end_dt:
# Calculate the end of the week (Monday 00:00:00, the threshold
# of Sunday-to-Monday.)
days_until_monday = 7 - current_start.weekday()
week_end = current_start + timedelta(days=days_until_monday)
week_end = week_end.replace(hour=0, minute=0, second=0, microsecond=0)

current_end = min(week_end, end_dt)
yield (current_start, current_end)

# Move to the next week (start of next Monday)
current_start = current_end + timedelta(days=1)
current_start = current_start.replace(
hour=0, minute=0, second=0, microsecond=0
)
current_start = current_end

def _attendance_intervals_batch(
self, start_dt, end_dt, resources=None, domain=None, tz=None
Expand Down

0 comments on commit ebe510f

Please sign in to comment.