New submission from Benedikt Bleimhofer <benedikt.bleimho...@gmail.com>:

It would probably save some people a lot of time if the documentation of 
datetime.replace 
(https://docs.python.org/3/library/datetime.html#datetime.datetime.replace) 
showed a warning not to use it for setting the timezone on a datetime object or 
at least that there is a high chance that the result will not be what you 
expect.

"
If you don't use tz.localize(), but use datetime.replace(), chances are that a 
historical offset is used instead; tz.localize() will pick the right offset in 
effect for the given date.
"
More information on the problem can be found here:
https://stackoverflow.com/questions/13994594/how-to-add-timezone-into-a-naive-datetime-instance-in-python

I ran into this problem and it took me quite some time to figure this out. 
datetime.replace seems more intuitive to use in this case, but since it does 
not work it might be useful to even link to tz.localize.

----------
assignee: docs@python
components: Documentation
messages: 365469
nosy: Benedikt Bleimhofer, docs@python
priority: normal
severity: normal
status: open
title: add warning to datetime.replace documentation to not use it for setting 
tzinfo unless UTC or None
type: enhancement

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40136>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to