# Time calculator failing tests

My code in my editor works perfectly, giving me the exact answers that are to be expected in the test, but when copying the code in the replit editor and putting it to the test, i get many errors as the following:

it shows as if the (number of days) part wasnt there, even tho in my editor the answer i get is the exact same as the expected in the test (the second smaller image is from my editor)

``````def add_time(start, duration, today = None):
time = ""
week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

start_time = start.split(" ")
start_hora, start_minuto = start_time[0].split(':')
start_hora, start_minuto = int(start_hora), int(start_minuto)
meridiano = start_time[1]

if meridiano == 'PM':
start_hora += 12

dur_hora, dur_minuto = duration.split(':')
dur_hora, dur_minuto = int(dur_hora), int(dur_minuto)

minutos = (start_minuto + dur_minuto) % 60
tot_horas  = (start_hora + dur_hora) + (start_minuto + dur_minuto) // 60
horas = tot_horas % 24
dias = tot_horas // 24

if horas >= 12:
if horas > 12:
horas %= 12 #ahora hacemos que el limite de horas sea de 12
meridiano = 'PM'
else:
meridiano = 'AM'

if horas == 0 and meridiano == 'AM':
horas = 12

time += str(horas) + ':'

if len(str(minutos)) == 1:
time += '0' + str(minutos)
else:
time += str(minutos)

time += ' ' + str(meridiano)

if dias:
if today:
today = today.title()
time += ', ' + week[(dias + week.index(today)) % 7]
if dias == 1:
time += " (next day)"
if dias > 1:
time += " (" + str(dias) + " days later)"
else:
if dias == 1:
time += " (next day)"
if dias > 1:
time += " (" + str(dias) + " days later)"
else:
if today:
time += ", " + today.title()

return time
``````

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

Challenge: Time Calculator

Your meridian takes every value more greater than 12 to be pm, when the day change you experience this trouble.
The 2 days later is due to this part

I dont seem to receive an error with the meridian, is only the last part. also by the tests in which only the actual day is expected and no the number of days that passed, it shows an error there too, even though in my editor is all fine. i dont really seem to find the problem, could you explain me a little more?

What “second image”?
If you mean the sliver at the bottom: that is missing the “`, Friday`” so that is wrong as well.

Honestly, I have never made specifically this project. But I can see some unnecessary complications in your code, so these are causing you trouble.

``````#For What the heck is today=none
time = start.split(" ")
meridian=time[1]

# would add a counter to the process.
while total_horas>= 24:
total_horas = total_horas- 24
total_days += 1

#Honestly I don't get why the code cannot be made simpler

if meridian== 'AM':
if int(total_horas) >= 12:
meridian='PM'
else:
meridian== 'PM':
if int(total_horas) >= 12:
meridian= "AM"
total_days += 1
``````

I made the code too fast(is advanced night here), so please correct me if I’m wrong, but I hope you get the point with this draft
Best Wishes

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.