# Scientific Computing with Python Projects - Time Calculator

Tell us what’s happening:
When I try my Time Calculator, the Test test_two_days_later & test_two_days_later_with_day fail.

The test is 11:59 PM + 24:05. My Calculator returns ‘0:04 AM (2 days later)’. But the test expects ‘12:04 AM (2 days later)’. But if I calculated it right 0:04 is the right answer. Did I just don’t understand AM and PM? Or is the testenprogramm wrong?

``````week = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']

def add_time(start, duration, day = None):

timeOfDay = start[-2:]
timeOfDay = timeOfDay.upper()
currentTime = start[:-3]

currentTime = currentTime.replace(':', '')
currentMin = int(currentTime[-2:])
currentHour = int(currentTime[:-2])

plusTime = duration.replace(':', '')
plusMin = int(plusTime[-2:])
plusHour = int(plusTime[:-2])

if currentHour > 12:
return "Exception: Give a hour from 0 - 11!"
if currentMin > 60:
return "Exception: Give a minute from 0 - 59!"

if timeOfDay == 'PM':
currentHour = currentHour + 12

totalHours = currentHour + plusHour + int((currentMin + plusMin) / 60)

days = int(totalHours / 24)

if totalHours >= 24 :
endHour = totalHours - (days * 24)
else:
endHour = totalHours

totalMin = (currentMin + plusMin) % 60

if endHour >= 12:
timeOfDay = 'PM'
else:
timeOfDay = 'AM'
if endHour >= 13:
endHour = endHour - 12

if totalMin < 10:
totalMin = '0' + str(totalMin)
else:
totalMin = str(totalMin)

if day == None:
if days == 0:
new_time = str(endHour) + ':' + totalMin + ' ' + timeOfDay
elif days == 1:
new_time = str(endHour) + ':' + totalMin + ' ' + timeOfDay + ' (next day)'
else:
new_time = str(endHour) + ':' + totalMin + ' ' + timeOfDay + ' (' + str(days) + ' days later)'
else:
day = day.lower()
day = day.capitalize()
if day in week:
for i in range(len(week)):
if day == week[i]:
newI = i + days
if newI >= 7:
newI = newI % 7
if days == 0:
new_time = str(endHour) + ':' + totalMin + ' ' + timeOfDay + ', ' + week[newI]
elif days == 1:
new_time = str(endHour) + ':' + totalMin + ' ' + timeOfDay + ', ' + week[newI] + ' (next day)'
else:
new_time = str(endHour) + ':' + totalMin + ' ' + timeOfDay + ', ' + week[newI] + ' (' + str(days) + ' days later)'

else:
return "This day does not exsist!"

return new_time
``````