Fixing a bug to differentiate between 23:59:59 and 24:00:00 end times

This commit is contained in:
Sam Splunks 2024-03-27 14:19:15 +00:00
parent cf81e0d452
commit f4bde19511
2 changed files with 11 additions and 7 deletions

View File

@ -198,6 +198,8 @@ def convert_value(value):
def daily_time_spent_calculation(earliest, latest, open_hours):
"""Returns the number of seconds for a single day time interval according to open hours."""
time_spent_seconds = 0
# avoid rendering day in different locale
weekday = ('monday', 'tuesday', 'wednesday', 'thursday',
'friday', 'saturday', 'sunday')[earliest.weekday()]
@ -215,7 +217,11 @@ def daily_time_spent_calculation(earliest, latest, open_hours):
# translate time for delta calculation
earliest_f = earliest.hour + earliest.minute / 60 + earliest.second / 3600
latest_f = latest.hour + latest.minute / 60 + latest.second / 3600
latest_f = latest.hour + latest.minute / 60 + latest.second / (60 * 60) + latest.microsecond / (60 * 60 * 999999)
# if latest time is midnight, add a second to the time spent
if latest_f >= 24:
time_spent_seconds += 1
if earliest_f < start:
earliest = earliest.replace(hour=start_hour, minute=start_minute, second=start_second)
@ -230,8 +236,6 @@ def daily_time_spent_calculation(earliest, latest, open_hours):
day_delta = latest - earliest
# returns up to 86399 seconds, add one second if full day
time_spent_seconds = day_delta.seconds
if time_spent_seconds == 86399:
time_spent_seconds += 1
time_spent_seconds += day_delta.seconds
return time_spent_seconds

View File

@ -1045,14 +1045,14 @@ class FollowUp(models.Model):
# close single day case
end_day_time = latest
else:
end_day_time = earliest.replace(hour=23, minute=59, second=59)
end_day_time = earliest.replace(hour=23, minute=59, second=59, microsecond=999999)
elif day == days:
start_day_time = latest.replace(hour=0, minute=0, second=0)
end_day_time = latest
else:
middle_day_time = earliest + datetime.timedelta(days=day)
start_day_time = middle_day_time.replace(hour=0, minute=0, second=0)
end_day_time = middle_day_time.replace(hour=23, minute=59, second=59)
end_day_time = middle_day_time.replace(hour=23, minute=59, second=59, microsecond=999999)
if (start_day_time.strftime("%Y-%m-%d") not in holidays and
prev_status not in exclude_statuses and