示例#1
0
 def __add__(self, other):
     if isinstance(other, Duration):
         return Duration(months=self[0] + int(other[0]), days=self[1] + int(other[1]),
                         seconds=self[2] + int(other[2]), subseconds=nano_add(self[3], other[3]))
     if isinstance(other, timedelta):
         return Duration(months=self[0], days=self[1] + int(other.days),
                         seconds=self[2] + int(other.seconds),
                         subseconds=nano_add(self[3], other.microseconds / 1000000))
     return NotImplemented
示例#2
0
 def __floordiv__(self, other):
     if isinstance(other, int):
         return Duration(months=int(self[0] // other),
                         days=int(self[1] // other),
                         seconds=int(nano_add(self[2], self[3]) // other),
                         subseconds=0)
     return NotImplemented
示例#3
0
 def __mod__(self, other):
     if isinstance(other, int):
         seconds, subseconds = symmetric_divmod(
             nano_add(self[2], self[3]) % other, 1)
         return Duration(months=round_half_to_even(self[0] % other),
                         days=round_half_to_even(self[1] % other),
                         seconds=seconds,
                         subseconds=subseconds)
     return NotImplemented