clock.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Clock:
    """
    Date-independent clock
    """
    def __init__(self, hour, minute):
        """
        Store the total minutes,
        making sure everything is wrapped around
        """
        self._total_min = (hour * 60 + minute) % (24 * 60)

    @property
    def hour(self):
        """The hour of the clock"""
        return self._total_min // 60

    @property
    def minute(self):
        """The minute of the clock"""
        return self._total_min % 60

    def __str__(self):
        return "%02d:%02d" % (self.hour, self.minute)

    def __eq__(self, other):
        """Compare to another Clock"""
        return self._total_min == other._total_min

    def add(self, minutes):
        """Return a new clock with minutes added"""
        return Clock(self.hour, self.minute + minutes)

@BrianLusina and @merlinli think this looks great

Comments


You're not logged in right now. Please login via GitHub to comment