**Tell us what’s happening:**

Could someone help me !

- I’m facing problems with some AM and PM
- For the next day
- and for one final day

for some tests the code is working well but not for all the tests

And thank you in advance for helping me !

**Your code so far**

```
def add_time(start_time, duration, start_day=False):
week = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
new_day = ""
hours_add = 0
hours = 0
start = start_time.split(" ")[0]
hours_st = start.split(":")[0]
minutes_st = start.split(":")[1]
form = start_time.split(" ")[1]
dur = duration
hours_dur = dur.split(":")[0]
minutes_dur = dur.split(":")[1]
#calculating sum of hours and sum of minutes
hours = int(hours_st) + int(hours_dur)
minut = int(minutes_st) + int(minutes_dur)
#calculating hours to add
if minut >= 60:
hours_add = (minut // 60)
minut = minut % 60
if minut <= 9:
minut = f"0{minut}"
hours += hours_add
days_add = hours // 24
#calculating days to add
if hours > 24:
days_add = hours / 24
if 0 < days_add - (hours//24) < 0.5:
days_add = hours // 24
elif days_add - (hours//24) > 0.5:
days_add = (hours // 24) + 1
else:
days_add = hours // 24
days_later = ""
hours = hours % 12
if hours == 0:
hours = 12
else:
hours = hours
form_nbflips = hours / 12
form_flip = {"AM":"PM", "PM":"AM"}
if form == "AM" and (int(hours_st) + int(hours_dur)) > 12:
form = "PM"
elif form == "PM" and (int(hours_st) + int(hours_dur)) > 12:
form = "AM"
if form_nbflips % 2 == 1:
form = form_flip[form]
else:
form = form
if form == "PM" and hours + (hours_add % 12) >= 12:
days_add += 1
if days_add == 1:
days_later = " (next day)"
if days_add > 1:
days_later = f" ({days_add} days later)"
if start_day:
d = str(start_day)
d = d.lower()
idx = week.index(d)
if days_add == 7:
new_day = d.capitalize()
if days_add > 7:
nday = (days_add % 7)
nday += idx
if nday >= 7:
nday = (days_add % 7)
new_day = week[nday].capitalize()
else:
nday = days_add + idx
new_day = week[nday].capitalize()
new_day = f" {new_day}"
if start_day:
final = f"{hours}:{minut} {form},{new_day}{days_later}"
else:
final = f"{hours}:{minut} {form}{days_later}"
return final
```

**Your browser information:**

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

**Challenge:** Time Calculator

**Link to the challenge:**