[Python-Dev] Status on PEP-431 Timezones
tim.peters at gmail.com
Tue Jul 28 09:27:53 CEST 2015
[delightful new insight elided, all summarized by what remains ;-) ]
>> What somedatetime+timedelta really does is simpler than that: it
>> adds the number of microseconds represented by the timedelta to
> No it doesn't.
Lennart, I wrote the code. Both the Python and C datetime
implementations. I know exactly what it does, and these repetitive
denials can't change that. Well, maybe they can. I really am just
assuming they can't ;-)
Here's, e.g., the Python code for datetime.__add__:
def __add__(self, other):
"Add a datetime and a timedelta."
if not isinstance(other, timedelta):
delta = timedelta(self.toordinal(),
delta += other
hour, rem = divmod(delta.seconds, 3600)
minute, second = divmod(rem, 60)
if 0 < delta.days <= _MAXORDINAL:
time(hour, minute, second,
raise OverflowError("result out of range")
There's not much to it. Apart from the year, month and date parts of
`self` (which are converted to an integer number of days), all the
rest is just adding integer microseconds expressed in two distinct
What part of that inspires your "No it doesn't"? It quite obviously
does, if you understand the code.
Your real objection (whether you realize it or not) is that it's not
converting to UTC at the start and back to self._tzinfo after.
But what does it matter? I'm done with this line. You can get what
you want, but it has to (according to me) be done in a
backward-compatible way (and see other msgs for ideas in that
More information about the Python-Dev