def do_update_user_activity_interval(user_profile: UserProfile, log_time: datetime.datetime) -> None:
    effective_end = (log_time + UserActivityInterval.MIN_INTERVAL_LENGTH)
    try:
        last = UserActivityInterval.objects.filter(user_profile=user_profile).order_by('-end')[0]
        if (((log_time <= last.end) and (log_time >= last.start)) or ((effective_end <= last.end) and (effective_end >= last.start))):
            last.end = max(last.end, effective_end)
            last.start = min(last.start, log_time)
            last.save(update_fields=['start', 'end'])
            return
    except IndexError:
        pass
    UserActivityInterval.objects.create(user_profile=user_profile, start=log_time, end=effective_end)
def do_update_user_activity_interval(user_profile: UserProfile, log_time: datetime.datetime) -> None:
    effective_end = (log_time + UserActivityInterval.MIN_INTERVAL_LENGTH)
    try:
        last = UserActivityInterval.objects.filter(user_profile=user_profile).order_by('-end')[0]
        if (((log_time <= last.end) and (log_time >= last.start)) or ((effective_end <= last.end) and (effective_end >= last.start))):
            last.end = max(last.end, effective_end)
            last.start = min(last.start, log_time)
            last.save(update_fields=['start', 'end'])
            return
    except IndexError:
        pass
    UserActivityInterval.objects.create(user_profile=user_profile, start=log_time, end=effective_end)