MCPcopy Index your code
hub / github.com/python/cpython / __add__

Method __add__

Lib/_pydatetime.py:2329–2346  ·  view source on GitHub ↗

Add a datetime and a timedelta.

(self, other)

Source from the content-addressed store, hash-verified

2327 return diff and 1 or 0
2328
2329 def __add__(self, other):
2330 "Add a datetime and a timedelta."
2331 if not isinstance(other, timedelta):
2332 return NotImplemented
2333 delta = timedelta(self.toordinal(),
2334 hours=self._hour,
2335 minutes=self._minute,
2336 seconds=self._second,
2337 microseconds=self._microsecond)
2338 delta += other
2339 hour, rem = divmod(delta.seconds, 3600)
2340 minute, second = divmod(rem, 60)
2341 if 0 < delta.days <= _MAXORDINAL:
2342 return type(self).combine(date.fromordinal(delta.days),
2343 time(hour, minute, second,
2344 delta.microseconds,
2345 tzinfo=self._tzinfo))
2346 raise OverflowError("result out of range")
2347
2348 __radd__ = __add__
2349

Callers

nothing calls this directly

Calls 5

timedeltaClass · 0.85
timeClass · 0.85
toordinalMethod · 0.80
fromordinalMethod · 0.80
combineMethod · 0.45

Tested by

no test coverage detected