Current implementation of `datetime.astimezone` (according to python 2/3
docs):
{{{
def astimezone(self, tz):
if self.tzinfo is tz:
return self
# Convert self to UTC, and attach the new time zone object.
utc = (self - self.utcoffset()).replace(tzinfo=tz)
# Convert from UTC to tz's local time.
return tz.fromutc(utc)
}}}
The implementation of `normalize` method for StaticTzInfo is `astimezone`:
{{{
if dt.tzinfo is self:
return dt
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
return dt.astimezone(self)
}}}
And for DstTzInfo `normalize` implementation is the same as
`datetime.astimezone`:
{{{
if dt.tzinfo is None:
raise ValueError('Naive time - no tzinfo set')
# Convert dt in localtime to UTC
offset = dt.tzinfo._utcoffset
dt = dt.replace(tzinfo=None)
dt = dt - offset
# convert it back, and return it
return self.fromutc(dt)
}}}
I've checked pytz 2011k and 2017.2 versions, looks like this code has
never changed.
Also I found this conversation
https://answers.launchpad.net/pytz/+question/249229
--
Ticket URL: <https://code.djangoproject.com/ticket/28323>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 0 => 1
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
[https://github.com/django/django/pull/8659 PR] -- the tests seems to
pass, so unless we're missing a test case to show why `normalize()` is
needed, I'd think your analysis is correct.
--
Ticket URL: <https://code.djangoproject.com/ticket/28323#comment:1>
--
Ticket URL: <https://code.djangoproject.com/ticket/28323#comment:2>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"bdf20c383f1a08248ec4be6cfc972c12dcbded04" bdf20c38]:
{{{
#!CommitTicketReference repository=""
revision="bdf20c383f1a08248ec4be6cfc972c12dcbded04"
Fixed #28323 -- Removed unneeded normalize() in timezone.localtime() and
make_naive().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28323#comment:3>
Comment (by Aymeric Augustin):
I was merely following the pytz docs, before they were updated in version
2016.4.
--
Ticket URL: <https://code.djangoproject.com/ticket/28323#comment:4>