def __add__(self,o): other = Duration(o,"DURATION") if not other.valid(): return Duration(0,"DURATION") seconds = self.utc_seconds() + other.seconds() new = Time(seconds,self.name(),self.timezone()) return new
def __add__(self, o): other = Duration(o, "DURATION") if not other.valid(): return Duration(0, "DURATION") print self.utc_seconds(), other.seconds() seconds = self.utc_seconds() + other.seconds() new = Time(seconds, self.name(), self.timezone()) return new
def __sub__(self, o): if isinstance(o, Time): # Subtract a time from this time and return a duration seconds = self.utc_seconds() - o.utc_seconds() return Duration(seconds) elif isinstance(o, Duration): # Subtract a duration from this time and return a time other = Duration(o) if (not other.valid()): return Time() seconds = self.utc_seconds() - other.seconds() return Time(seconds) else: raise TypeError, "subtraction with Time reqires Time or Duration"
def __sub__(self,o): if isinstance(o,Time): # Subtract a time from this time and return a duration seconds = self.utc_seconds() - other.utc_seconds() return Duration(seconds) elif isinstance(o,Duration): # Subtract a duration from this time and return a time other = Duration(o) if(not other.valid()): return Time() seconds = self.utc_seconds() - other.seconds() return Time(seconds) else: raise TypeError, "subtraction with Time reqires Time or Duration"
#!/usr/bin/env python