been spending hours and hours to try and figure out why it is not working but with no success, appreciated if some guidance can be made what mistakes were make and what can be improved on as a beginner.
def add_time(start, duration, days=False):
current_time = start.split(':')
current_time_mins = current_time[1].split()
current_hrs = int(current_time[0])
current_mins = int(current_time_mins[0])
current_meridiem = current_time_mins[1]
meridiem_changes = {"AM": "PM", "PM": "AM"}
added_time = duration.split(":")
added_hrs = int(added_time[0])
added_mins = int(added_time[1])
the_days_in_the_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
the_days_in_the_week_with_index = {"monday": 0, "tuesday": 1, "wednesday": 2, "thursday": 3, "friday": 4, "saturday": 5, "sunday": 6 }
num_of_days = int(added_hrs/24)
new_mins = current_mins + added_mins
if new_mins > 59 :
current_hrs += 1
new_mins %= 60
new_hrs = (current_hrs + added_hrs) % 12
num_of_meridiem_changes = int((current_hrs + added_hrs)/12)
if new_mins >= 10 :
new_mins = new_mins
else:
"0" + str(new_mins)
if new_hrs == 0 :
new_hrs = 12
else:
new_hrs = new_hrs
if current_meridiem == "PM" and current_hrs + (added_hrs%12) >= 12 :
num_of_days += 1
if num_of_meridiem_changes % 2 == 1 :
current_meridiem = meridiem_changes[current_meridiem]
else:
current_meridiem = current_meridiem
new_time = str(new_hrs) + ":" + str(new_mins) + " " + current_meridiem
if (days) :
days = days.lower()
index = int((the_days_in_the_week_with_index[days]) + num_of_days) % 7
new_days = the_days_in_the_week[index]
new_time = ", " + new_days
if num_of_days == 1 :
return new_time + " " + "(next day)"
elif num_of_days > 1 :
return new_time + " (" + str(num_of_days) + " days later)"
return new_time