diff --git a/src/genpy/rostime.py b/src/genpy/rostime.py index a1fd9cc..6206a18 100644 --- a/src/genpy/rostime.py +++ b/src/genpy/rostime.py @@ -406,7 +406,7 @@ def __floordiv__(self, val): elif t == float: return Duration.from_sec(self.to_sec() // val) elif isinstance(val, Duration): - return self.to_sec() // val.to_sec() + return int(self.to_sec() // val.to_sec()) else: return NotImplemented @@ -446,6 +446,28 @@ def __truediv__(self, val): else: return NotImplemented + def __mod__(self, val): + """ + Find the remainder when dividing this Duration by another Duration + :returns: :class:`Duration` The remaining time after the division + """ + if isinstance(val, Duration): + return Duration.from_sec(self.to_sec() % val.to_sec()) + else: + return NotImplemented + + def __divmod__(self, val): + """ + Implements the builtin divmod for a pair of Durations + :returns: ``int`` The floored result of the division + :returns: :class:`Duration` The remaining time after the division + """ + if isinstance(val, Duration): + quotient, remainder = divmod(self.to_sec(), val.to_sec()) + return int(quotient), Duration.from_sec(remainder) + else: + return NotImplemented + def __cmp__(self, other): if not isinstance(other, Duration): raise TypeError("Cannot compare to non-Duration")