Tell us what’s happening:
I have all of the tasks done apart from ‘Expected time to end with ‘(next day)’ when it is the next day.’
I’ve tested from 21hrs duration which is 11:59pm the same day up to 48hrs duration which is ‘2 days later’ and all looks good, it changes to ‘(next day)’ when the returnTime hits 12:59am at 22hrs duration and stays there until 48hrs duration when it changes to ‘2 days later’ but still not saying correct
Your code so far
def add_time(start, duration, day_of_week= False):
days_of_week_index = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3, 'Friday': 4, 'Saturday': 5, 'Sunday': 6}
days_of_the_week_array = ['Monday', 'Tuesday', 'Wednesday','Thursday', 'Friday', 'Saturday', 'Sunday']
duration_tuple = duration.partition(":")
duration_hours = int(duration_tuple[0])
duration_minutes = int(duration_tuple[2])
start_tuple = start.partition(":")
start_minutes_tuple = start_tuple[2].partition(" ")
start_hours = int(start_tuple[0])
start_minutes = int(start_minutes_tuple[0])
am_or_pm = start_minutes_tuple[2]
am_and_pm_flip = {'AM': 'PM', 'PM': 'AM'}
#print(start_hours)
# print(duration_hours)
amount_of_days = int(duration_hours) / 24
end_minutes = start_minutes + duration_minutes
#print(end_minutes)
if end_minutes >= 60:
start_hours += 1
end_minutes = end_minutes % 60
amount_of_am_pm_flips = int((start_hours + duration_hours) / 12)
end_hours = start_hours + duration_hours
#print(end_minutes)
#print(end_hours)
end_minutes = end_minutes if end_minutes > 9 else '0' + str(end_minutes)
end_hours = end_hours = 12 if end_hours % 12 == 0 else end_hours % 12
if am_or_pm == 'PM' and start_hours + (duration_hours // 12) >= 12:
amount_of_days += 1
elif am_or_pm == 'PM' and amount_of_am_pm_flips >= 1:
amount_of_days += 1
am_or_pm = am_and_pm_flip[am_or_pm] if amount_of_am_pm_flips % 2 == 1 else am_or_pm
print(amount_of_am_pm_flips)
print(amount_of_days)
returnTime = str(end_hours) + ':' + str(end_minutes) + ' ' + am_or_pm
if day_of_week:
day_of_week = day_of_week.lower()
day_of_week = day_of_week[0].upper() + day_of_week[1:]
index = int((days_of_week_index[day_of_week]) + amount_of_days) % 7
new_day = days_of_the_week_array[index]
returnTime += ', ' + new_day
if amount_of_days == 1:
return returnTime +' ' + '(next day)'
elif amount_of_days < 2 and amount_of_am_pm_flips > 1:
return returnTime +' ' + '(next day)'
elif amount_of_days >= 2:
return returnTime + ' (' + str(int(amount_of_days)) + ' days later)'
return returnTime
print(add_time('2:59 AM', '21:00'))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Challenge Information:
Build a Time Calculator Project - Build a Time Calculator Project