Skip to content

Time.hour in base 60 is weird in chapter 14. #58

@alchemistcai

Description

@alchemistcai

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions