# Untitled

unknown
python
2 years ago
1.8 kB
30
Indexable
Never
time = ""
week = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
s_time, meridiem = start.split(" ") # Splitting time and meridiem
s_hour, s_minute = s_time.split(":") # Splitting hour and minute
s_hour, s_minute = int(s_hour), int(s_minute) # Converting hour and minute to int
d_hour, d_minute = duration.split(":") # Time to be added.
d_hour, d_minute = int(d_hour), int(d_minute)
minute = (s_minute + d_minute) % 60 # Total minutes
total_hours = (s_hour + d_hour) + ((s_minute + d_minute) // 60) # Total hours
days = total_hours // 24
hour = total_hours % 24
print('Minute:', minute)
print("Total Hours:",total_hours)
print("Hours:", hour)
print("Days: ", days) # Error in Days. Build a different formula.

if hour >= 12 and hour<24:
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

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()

return time

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