Code for Instant (Moment in time) Class in Python


class Instant:
	
	def __init__(self,year,month,day,hour,minute):
		if not ((type(year) != type(2000)) or (year < 1900) or (year > 2100)): self.__year = year 
		else: raise Exception('Year is not in correct format or out of range')
		if not ((type(month) != type(2000)) or (month < 0) or (month > 12)): self.__month = month		
		else: raise Exception('Month is not in correct format or out of range')
		if not ((type(day) != type(2000)) or (day < 0) or (day > 31)): self.__day = day 		
		else: raise Exception('Day is not in correct format or out of range')
		if not ((type(hour) != type(24)) or (hour < 0) or (hour > 24)): self.__hour = hour
		else: raise Exception('Hour is not in correct format or out of range')
		if not ((type(minute) != type(2000)) or (minute < 0) or (minute > 60)): self.__minute = minute
		else: raise Exception('Minute is not in correct format or out of range')
		
	def getYear(self):
		return self.__year
		
	def getMonth(self):
		return self.__month
		
	def getDay(self):
		return self.__day
		
	def getHour(self):
		return self.__hour
		
	def getMinute(self):
		return self.__minute
		
	def setYear(self,year):
		if not ((type(year) != type(2000)) or (year < 1900) or (year > 2100)):
			self.__year = year 
			
	def setMonth(self,month):
		if not ((type(month) != type(2000)) or (month < 0) or (month > 12)):
			self.__month = month 
			
	def setDay(self,day):
		if not ((type(day) != type(2000)) or (day < 0) or (day > 31)):
			self.__day = day 
			
	def setHour(self,hour):
		if not ((type(hour) != type(24)) or (hour < 0) or (hour > 24)):
			self.__hour = hour 
	
	def setMinute(self,minute):
		if not ((type(minute) != type(2000)) or (minute < 0) or (minute > 60)):
			self.__minute = minute 
			
	def beforeMe(self,other):
		if self.__year > other.getYear():
			return False
		elif self.__year == other.getYear():
			if self.__month > other.getMonth():
				return False
			elif self.__month == other.getMonth():
				if self.__day > other.getDay():
					return False
				elif self.__day == other.getDay():
					if self.__hour > other.getHour():
						return False
					elif self.__hour == other.getHour():
						if self.__minute > other.getMinute():
							return False
		return True
				
	def afterMe(self,other):
		return not self.beforeMe(other)
		
	def add(self,min):
		if type(min) != type(1): raise Exception("Invalid mintues to add")
		self.__minute += min
		if self.__minute > 60:
			self.__hour += self.__minute / 60
			self.__minute = self.__minute % 60
			if self.__hour > 24:
				self.__day += self.__hour / 24
				self.__hour = self.__hour % 24
				if self.__day > 30:
					self.__month += self.__day / 30
					self.__day = self.__day % 30
					if self.__month > 12:
						self.__year += self.__month / 12
						self.__month = self.__month % 12
		
	def __str__(self):	
		return  str(self.__month) + "/" + str(self.__day) + "/" + str(self.__year) + " " + \
				str(self.__hour) + ":" + str(self.__minute)