def __sub__(self, other):
        "Subtract two datetimes, or a datetime and a timedelta."
        if not isinstance(other, datetime):
            if isinstance(other, timedelta):
                return self._add_timedelta(other, -1)
            return NotImplemented

        delta_d = self.toordinal() - other.toordinal()
        delta_s = (self._hour - other._hour) * 3600 + \
                  (self._minute - other._minute) * 60 + \
                  (self._second - other._second)
        delta_us = self._microsecond - other._microsecond
        base = timedelta._create(delta_d, delta_s, delta_us, True)
        if self._tzinfo is other._tzinfo:
            return base
        myoff = self._utcoffset()
        otoff = other._utcoffset()
        if myoff == otoff:
            return base
        if myoff is None or otoff is None:
            raise TypeError("can't subtract offset-naive and offset-aware datetimes")
        return base + timedelta(minutes = otoff-myoff)
def __sub__ ( self , other ) : if not isinstance ( other , datetime ) : if isinstance ( other , timedelta ) : return self . _add_timedelta ( other , - 1 ) return NotImplemented delta_d = self . toordinal ( ) - other . toordinal ( ) delta_s = ( self . _hour - other . _hour ) * 3600 + ( self . _minute - other . _minute ) * 60 + ( self . _second - other . _second ) delta_us = self . _microsecond - other . _microsecond base = timedelta . _create ( delta_d , delta_s , delta_us , True ) if self . _tzinfo is other . _tzinfo : return base myoff = self . _utcoffset ( ) otoff = other . _utcoffset ( ) if myoff == otoff : return base if myoff is None or otoff is None : raise TypeError ( "can't subtract offset-naive and offset-aware datetimes" ) return base + timedelta ( minutes = otoff - myoff )
Subtract two datetimes, or a datetime and a timedelta.