#28323: Redundant use of `normalize` in `django.utils.localtime`
---------------------------------------------+------------------------
Reporter: Sergey Zherevchuk | Owner: nobody
Type: Uncategorized | Status: new
Component: Utilities | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
I'm not 100% sure , but I didn't find any test on this and can't think of
any.
What the purpose of using `timezone.normalize` method after
`dt.astimezone` if pytz installed?
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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.051709e01d5beb3460904df4c0feb414%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.