Build a Time Calculator Project - Build a Time Calculator Project

Tell us what’s happening:

I don’t know the problem with (Expected time to end with ‘(next day)’ when it is the next day.) can someone help me ?

Your code so far

def calculate_time(minute_start,minute_duration,hour_start,hour_duration, meridiem, day):
    new_hour = 0
    new_minute = 0
    added_hour = 0
    days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
    if int(minute_start) + int(minute_duration) < 60:
        new_minute = int(minute_start) + int(minute_duration)
    else:
        new_minute = (int(minute_start) + int(minute_duration)) % 60
        added_hour = (int(minute_start) + int(minute_duration)) // 60
    if len(str(new_minute)) == 1:
        new_minute = '0' + str(new_minute)
        
    new_hour = int(hour_start) + int(hour_duration) + added_hour
    if meridiem == 'PM':
        elapsed_days = (new_hour + 12) // 24
    else:
        elapsed_days = new_hour // 24
    if day:
        day_index = days.index(day.lower())
        new_day_index = (day_index + elapsed_days) % 7
        new_day = days[new_day_index].capitalize()
        print(new_day)
    if elapsed_days == 1:
        if not (new_hour // 12) % 2:
            new_hour = new_hour % 12
        if new_hour > 12:
                new_hour = new_hour % 12
                meridiem = 'PM'
        elif new_hour == 12:
            meridiem = 'PM'
        if not day:
            return f'{new_hour}:{new_minute} {meridiem} (next day)'
        else:
            return f'{new_hour}:{new_minute} {meridiem}, {new_day} (next day)'
    elif elapsed_days == 0:
        if not (new_hour // 12) % 2:
            new_hour = new_hour % 12
        if new_hour > 12:
            new_hour = new_hour % 12
            meridiem = 'PM'
        elif new_hour == 12:
            meridiem = 'PM'
        if not day:
            return f'{new_hour}:{new_minute} {meridiem}'
        else:
            return f'{new_hour}:{new_minute} {meridiem}, {new_day}'
        
    else: 
        if not (new_hour // 12) % 2:
            if new_hour % 12 == 0:
                new_hour = 12
            else:
                new_hour = new_hour % 12
        if new_hour == range(12,23):
                new_hour = new_hour % 12
                meridiem = 'PM'
        else:
            if new_hour % 12 == 0:
                new_hour = 12
            else:
                new_hour = new_hour % 12
            meridiem = 'AM'
        if not day:
            return f'{new_hour}:{new_minute} {meridiem} ({elapsed_days} days later)'
        else:
            return f'{new_hour}:{new_minute} {meridiem}, {new_day} ({elapsed_days} days later)'
def add_time(start, duration, day=''):
    new_time = []
    hour_start = start[:start.index(":")]
    minute_start = start[start.index(":")+1:start.index(":")+3]
    meridiem = start[start.index(":")+4:]
    hour_duration = duration[:duration.index(":")]
    minute_duration = duration[duration.index(":")+1:]
    return calculate_time(minute_start,minute_duration,hour_start,hour_duration, meridiem, day)
    


print(repr(add_time('11:59 PM', '12:05', 'Wednesday')))

    

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0

Challenge Information:

Build a Time Calculator Project - Build a Time Calculator Project

I am not sure the issue is with ‘next day’

if you use this function
print(repr(add_time('11:59 PM', '00:05', 'Wednesday'))), the time should be 12:04 AM, what does your function return?