Returns the difference between two Time objects as an Duration. :param dt: The time to subtract from :param abs: Whether to return an absolute duration or not
(self, dt: time | None = None, abs: bool = True)
| 213 | # DIFFERENCES |
| 214 | |
| 215 | def diff(self, dt: time | None = None, abs: bool = True) -> Duration: |
| 216 | """ |
| 217 | Returns the difference between two Time objects as an Duration. |
| 218 | |
| 219 | :param dt: The time to subtract from |
| 220 | :param abs: Whether to return an absolute duration or not |
| 221 | """ |
| 222 | if dt is None: |
| 223 | dt = pendulum.now().time() |
| 224 | else: |
| 225 | dt = self.__class__(dt.hour, dt.minute, dt.second, dt.microsecond) |
| 226 | |
| 227 | us1 = ( |
| 228 | self.hour * SECS_PER_HOUR + self.minute * SECS_PER_MIN + self.second |
| 229 | ) * USECS_PER_SEC |
| 230 | |
| 231 | us2 = ( |
| 232 | dt.hour * SECS_PER_HOUR + dt.minute * SECS_PER_MIN + dt.second |
| 233 | ) * USECS_PER_SEC |
| 234 | |
| 235 | klass = Duration |
| 236 | if abs: |
| 237 | klass = AbsoluteDuration |
| 238 | |
| 239 | return klass(microseconds=us2 - us1) |
| 240 | |
| 241 | def diff_for_humans( |
| 242 | self, |