Time.py
Classe Time em python
Size 1.9 kB - File type text/python-sourceFile contents
class Time: """ Class Time """ def __init__(self, hour = 0, minute = 0, second = 0): """ Construtor da classe Time""" self.__hour = hour self.__minute = minute self.__second = second def setTime(self, hour, minute, second): """ Set values of Hour, Minute and Second """ self.setHour(hour) self.setMinute(minute) self.setSecond(second) def setHour(self,hour): """Set Hour value""" if 0<= hour < 24: self.__hour = hour else: raise ValueError, "Invalid Hour Value: %d" % hour def setMinute(self,minute): """Set Minute value""" if 0<= minute < 60: self.__minute = minute else: raise ValueError, "Invalid Minute Value: %d" % Minute def setSecond(self,second): """Set Second value""" if 0<= second < 60: self.__second = second else: raise ValueError, "Invalid Second Value: %d" % Second def getHour(self): """Get Hour Value""" return self.__hour def getMinute(self): """Get Minute Value""" return self.__minute def getSecond(self): """Get Second Value""" return self.__second def printMilitary(self): """Prints Time Object in Military Format""" print "%.2d:%.2d:%.2d" % \ (self.__hour, self.__minute, self.__second), def printStandardTime(self): """Prints Tiem object in standard format """ standardTime = " " if self.__hour == 0 or self.__hour == 12: standardTime += "12:" else: standardTime += "%d:" % (self.__hour %12) standardTime += "%.2d:%.2d" % (self.__minute, self.__second) if self.__hour < 12: standardTime += " AM" else: standardTime += " PM" print standardTime,