-
Notifications
You must be signed in to change notification settings - Fork 899
Open
Description
In chapter 14 section Prototype and patch,hour%60 is unusual, as hour is usually in base 12 or 24 or 10.
If 59:59:59 is valid,I think 159:59:59 is valid too.
The result is a valid time. We can do the same thing with hour and second, and encapsulate the whole process in a function.
def increment_time(time, hours, minutes, seconds):
time.hour += hours
time.minute += minutes
time.second += seconds
carry, time.second = divmod(time.second, 60)
carry, time.minute = divmod(time.minute + carry, 60)
carry, time.hour = divmod(time.hour + carry, 60) # weird
Related description in chapter 14 section Design-first development is strange too,as sexagesimal
is mainly for minutes and seconds.
In this case, the insight is that we can think of a Time object as a three-digit number in base 60-- also known as sexagesimal
Metadata
Metadata
Assignees
Labels
No labels