/examples/dynamictable/TimeSlot.py

http://pyjamas.googlecode.com/ · Python · 38 lines · 32 code · 6 blank · 0 comment · 8 complexity · 49d94e6fb6240998d6f3abd7b76ef483 MD5 · raw file

  1. import math
  2. class TimeSlot:
  3. def __init__(self, dayOfWeek, startMinutes, endMinutes):
  4. self.DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
  5. self.dayOfWeek = dayOfWeek
  6. self.startMinutes = startMinutes
  7. self.endMinutes = endMinutes
  8. def compareTo(self, other):
  9. if self.dayOfWeek < other.dayOfWeek:
  10. return -1
  11. elif self.dayOfWeek > other.dayOfWeek:
  12. return 1
  13. else:
  14. if self.startMinutes < other.startMinutes:
  15. return -1
  16. elif self.startMinutes > other.startMinutes:
  17. return 1
  18. return 0
  19. def getDayOfWeek(self):
  20. return self.dayOfWeek
  21. def getDescription(self):
  22. return self.DAYS[self.dayOfWeek] + " " + self.getHrsMins(self.startMinutes) + "-" + self.getHrsMins(self.endMinutes)
  23. def getHrsMins(self, mins):
  24. hrs = math.floor(mins / 60)
  25. if hrs > 12:
  26. hrs -= 12
  27. remainder = math.floor(mins % 60)
  28. if remainder < 10:
  29. string_mins = "0" + str(remainder)
  30. else:
  31. string_mins = str(remainder)
  32. return str(hrs) + ":" + string_mins