Tell us what’s happening:
I have pass almost every test case of Time Calculator project except one case that I’m not clear about the requirement:
Test Case #8 Expected adding 0:00 to return the initial time.
I’m not sure what is the expectation for which scenario so that I will pass this test case. Could someone help me clarifying this?
Thank you very much for your help
Chawalit
Your code so far
def add_time(start, duration, start_day=''):
days = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
new_time = ''
start_time, start_am_pm = start.split(' ')
start_hour, start_minute = start_time.split(':')
duration_hour, duration_minute = duration.split(':')
# Adjust to 24 hours format
if start_am_pm == 'PM':
start_hour = str( int(start_hour) + 12 )
new_minute = str(int(start_minute) + int(duration_minute))
if int(new_minute) >= 60:
duration_hour = str(int(duration_hour) + 1)
new_minute = f"{int(new_minute) % 60:0>2}"
new_hour = str(int(start_hour) + int(duration_hour))
if int(new_hour) >= 24:
days_later = int(new_hour) // 24
else:
days_later = 0
day_info = ""
if start_day:
for i, day in enumerate(days):
if day.lower() == start_day.lower():
day_info =", "
day_info += day if days_later == 0 else days[(i+days_later) % 7]
if days_later > 0:
day_info += " (next day)" if days_later == 1 else f" ({days_later} days later)"
# AM when less than 12 hours
new_am_pm = 'AM' if int(new_hour) % 24 < 12 else 'PM'
# Adjust to 12 hours format
new_hour = str(int(new_hour) % 12)
if int(new_hour) == 0:
new_hour = '12'
new_time = f'{new_hour}:{new_minute} {new_am_pm}{day_info}'
return new_time
print( add_time('8:16 PM', '0:00') )
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Build a Time Calculator Project - Build a Time Calculator Project
