Build a Time Calculator Project - Build a Time Calculator Project

Tell us what’s happening:

I am not sure why I am only failing test cases 3 and 4 here. The things it is asking for appear to be happening in all of the other later test cases so I’m not sure what these more general two cases are asking. It’s very unclear.

Your code so far

MAX_HOUR = 12
MAX_MINUTE = 59
DAYS_OF_WEEK = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']

def add_time(start, duration, day = ''):
    # Split start input into separate variables
    start_split = start.split(':')
    start_sub_split = start_split[1].split(' ')
    start_hr = start_split[0]
    start_min = start_sub_split[0]
    start_half = start_sub_split[1].upper()
    # Split duration input into separate variables
    duration_split = duration.split(':')
    duration_hr = duration_split[0]
    duration_min = duration_split[1]
    remaining_hr = int(duration_hr)

    # Find raw modified times
    raw_hr = int(start_hr) + int(duration_hr)
    if start_half == 'PM':
        raw_hr += 12
    raw_min = int(start_min) + int(duration_min)
    raw_day = day.title()
    if day:
        raw_day_index = DAYS_OF_WEEK.index(raw_day) + 1
        new_day_index = 0
        #print(raw_day_index)
    
    # Find new modified times
    new_hr = raw_hr % 24
    new_min = str(raw_min % 60).zfill(2)
    new_half = start_half

    # Roll over minutes
    if raw_min > MAX_MINUTE:
        new_hr += 1 * (int(raw_min) // 60)
        remaining_hr += 1 * (int(raw_min) // 60)

    # Set half
    if new_hr < 12:
        new_half = 'AM'
    else:
        new_half = 'PM'

    # Day passage setup
    time_to_next_day = 24 - new_hr
    day_counter = 0
    
    # Day passage calculation
    if remaining_hr == 24:
        day_counter = 1
    elif remaining_hr > time_to_next_day:
        day_counter += 1 + (1 * (remaining_hr // 24))
    
    # Create day string
    if day_counter == 1:
        day_string = '(next day)'
        if day:
            new_day_index = (raw_day_index + day_counter) % 7
    elif day_counter > 1:
        day_string = f'({day_counter} days later)'
        if day:
            new_day_index = (raw_day_index + day_counter) % 7
            #print(new_day_index)
    else:
        day_string = ''
        if day:
            new_day_index = raw_day_index
    


    # Switch from 24 HR to 12 HR time
    new_hr = new_hr % 12
    if new_hr == 0:
        new_hr = 12
        new_half = 'AM'

    # Construct final string
    new_time = f'{new_hr}:{new_min} {new_half}'
    if day:
        new_time += f', {DAYS_OF_WEEK[new_day_index - 1]}'
    if day_string:
        new_time += f' {day_string}'
    print(repr(new_time))




    return new_time


add_time('3:30 PM', '2:12')
add_time('11:55 AM', '3:12')
add_time('2:59 AM', '24:00')
add_time('11:59 PM', '24:05')
add_time('8:16 PM', '466:02')
add_time('3:30 PM', '2:12', 'Monday')
add_time('2:59 AM', '24:00', 'saturDay')
add_time('11:59 PM', '24:05', 'Wednesday')
add_time('8:16 PM', '466:02', 'tuesday')

Your browser information:

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

Challenge Information:

Build a Time Calculator Project - Build a Time Calculator Project

in this case print(add_time("9:15 PM", "5:30")) it doesn’t say “next day” and print(add_time("11:40 AM", "0:25")) doesn’t change the AM/PM properly