# Need help regarding time calculator, failing one test

I’m currently doing the time calculator challenge
its done, passing every test apart from 3rd one( Expected time to end with `'(next day)'` when it is the next day.)
Its passing the 5th one ( Calling `add_time('2:59 AM', '24:00')` should return `'2:59 AM (next day)'` .) which is an extension of 3rd one

code:

``````def add_time(start, duration,wday=''):
start=start.replace(":"," ").split()
duration=duration.replace(":"," ").split()
meri=["AM","PM"]
d=meri.index(start[2])
meri=meri[d:]+meri[:d]
weekdays=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
while True:
#start time
hr=int(start[0])
#given time
dhr=int(duration[0])
#start min
mn=start[1]
#given min
gmn=int(duration[1])
dmn=int(duration[1])+int(mn)
days=0
nd=0
day=0
mrd=""
if dmn>=60:
dmn-=60
hr+=1
meridiem=start[2]
if dhr<=12:
hr+=dhr
if meridiem=="AM" and hr>=12:
if hr==12:
pass
else:
hr=hr-12
nd=~nd
print("w")
elif meridiem=="PM" and hr>12:
hr=hr-12
day+=1
nd=0
elif meridiem=="AM" and hr<12:
if hr==12:
nd=~nd
pass
else:
hr+dhr
mrd=meri[nd]
break
elif dhr>=24:
day=0
if dhr==24 and gmn==0:
days=1
else:
days=(dhr//24)+1
if gmn!=0:
mhr=dhr*60+dmn
else:
mhr=dhr*60
thr=0
while mhr>=0:
thr+=1
if thr==60:
thr=0
if hr>12:
hr=1
nd+=1
if nd==1:
mrd=meri[~(nd-1)]
if nd==2:
mrd=meri[~(nd-1)]
if nd==2:
day+=1
if(hr+dhr)*60>1440:
g=1
nd=1
mrd=meri[~nd]
hr+=1
mhr-=1
if hr>12:
hr-=12
if gmn==0:
mrd=meri[~nd]
else:
mrd=meri[nd]
break
elif meridiem=="PM" and dhr>12 and dhr<24:
days=dhr//12
dhr=dhr%12
else:
pass
fd=""
if len(str(dmn))==1:
dmn="0"+str(dmn)
if len(wday)!=0:
wday=wday.capitalize()
cnt=days%7
o=weekdays.index(wday)
weekdays=weekdays[o:]+weekdays[:o]
fd=", "+weekdays[cnt]
new_time=f"{hr}:{dmn} {mrd}{fd}"
if days==1:
new_time+=" (next day)"
elif days>1:
new_time+=f' ({days} days later)'
print(new_time)
return new_time

``````

can anyone tell me whats the problem?

in the instruction, the give some examples:

``````add_time('10:10 PM', '3:30')
# Returns: 1:40 AM (next day)
``````

it doesn’t pass that one, even if it’s not in the tests, it may affect the third test

1 Like

and this one should say

1:00 AM (next day)

apparently it has problems when it’s close to midnight

1 Like

Thank you, I was stuck for about 3-4 hrs due to this issue.

1 Like