# Need help in Time calculator

Tell us what’s happening:
Describe your issue in detail here.

Save New Duplicate & Edit Just Text Twitter

``````def add_time(start, duration, today=None):
time = ""
week = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
s_time, meridiem = start.split(" ")
s_hour, s_minute = s_time.split(":")
s_hour, s_minute = int(s_hour), int(s_minute)
d_hour, d_minute = duration.split(":")
d_hour, d_minute = int(d_hour), int(d_minute)
minute = (s_minute + d_minute) % 60
total_hours = (s_hour + d_hour) + ((s_minute + d_minute) // 60)
days = total_hours // 24
hour = total_hours % 24
print('Minute:', minute)
print("Total Hours:",total_hours)
print("Hours:", hour)

if hour >= 12:
if hour > 12:
hour %= 12
meridiem = "PM"
else:
meridiem = "AM"

time += str(hour) + ":"

if len(str(minute)) == 1:
time += "0" + str(minute)
else:
time += str(minute)

time += " " + meridiem

print("Days: ",days) # Error in Days
if days:
next_day = days % 7
if today:
today = today.title()
# print(((next_day + week.index(today)) % 7))
time += ", " + week[((next_day + week.index(today) ) % 7)] # Code worked but logic is still need to be cleared.
else:
if next_day > 1:
time += str(f"{next_day} days later")
if next_day == 1:
time += " (next day)"
else:
if today:
time += ", "+ today.title()

# if meridiem == "AM":
#     if ((s_hour + d_hour) // 11) % 2 != 0:
#         meridiem = "PM"

# if meridiem == "PM":
#     if ((s_hour + d_hour) // 11) % 2 == 0:
#         meridiem = "AM"

return time

print(add_time("11:59 PM", "24:05", "Wednesday")) # expected O/P "00:03 AM Thursday"

# Returns: 6:10 PM

# Returns: 2:02 PM, Monday

# Returns: 12:03 PM

# Returns: 1:40 AM (next day)

# Returns: 12:03 AM, Thursday (2 days later)

# Returns: 7:42 AM (9 days later) """
``````

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

Challenge: Time Calculator

Hey can anyone help me out here?

Sure, can you tell us what the problem is?

Not getting proper logic which should be applied for days and meridiam.
For ex: Current time = “11:59 PM”,