PageRenderTime 39ms CodeModel.GetById 31ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/examples/dynamictable/TimeSlot.py

http://pyjamas.googlecode.com/
Python | 38 lines | 32 code | 6 blank | 0 comment | 4 complexity | 49d94e6fb6240998d6f3abd7b76ef483 MD5 | raw file
 1import math
 2
 3class TimeSlot:
 4    def __init__(self, dayOfWeek, startMinutes, endMinutes):
 5        self.DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
 6        self.dayOfWeek = dayOfWeek
 7        self.startMinutes = startMinutes
 8        self.endMinutes = endMinutes
 9    
10    def compareTo(self, other):
11        if self.dayOfWeek < other.dayOfWeek:
12            return -1
13        elif self.dayOfWeek > other.dayOfWeek:
14            return 1
15        else:
16            if self.startMinutes < other.startMinutes:
17                return -1
18            elif self.startMinutes > other.startMinutes:
19                return 1
20        return 0
21
22    def getDayOfWeek(self):
23        return self.dayOfWeek
24
25    def getDescription(self):
26        return self.DAYS[self.dayOfWeek] + " " + self.getHrsMins(self.startMinutes) + "-" + self.getHrsMins(self.endMinutes)
27        
28    def getHrsMins(self, mins):
29        hrs = math.floor(mins / 60)
30        if hrs > 12:
31            hrs -= 12
32        remainder = math.floor(mins % 60)
33        if remainder < 10:
34            string_mins = "0" + str(remainder)
35        else:
36            string_mins = str(remainder)
37        return str(hrs) + ":" + string_mins
38