[issue9063] TZ examples in datetime.rst are incorrect
New submission from Alexander Belopolsky
exec(open('Doc/includes/tzinfo-examples.py').read()) import os os.environ['TZ'] 'US/Eastern' from datetime import * x = datetime(2010, 11, 7, 5, tzinfo=timezone.utc) print(x, x.astimezone(Local), x.astimezone(Eastern)) 2010-11-07 05:00:00+00:00 2010-11-07 01:00:00-04:00 2010-11-07 01:00:00-05:00 x.astimezone(Local).dst() == x.astimezone(Eastern).dst() False
Note that according to my understanding of the long comment at the end of datetimemodule.c, zone conversion from UTC is a well defined operation unless there is a bug in tzinfo subclass implementation.
----------
assignee: docs@python
components: Documentation
messages: 108462
nosy: belopolsky, docs@python
priority: normal
severity: normal
stage: needs patch
status: open
title: TZ examples in datetime.rst are incorrect
versions: Python 2.7, Python 3.2
_______________________________________
Python tracker
Alexander Belopolsky
x == x.astimezone(Eastern) False
while
x == x.astimezone(Local) True
----------
_______________________________________
Python tracker
Alexander Belopolsky
import time def print_time(s): ... tt = time.localtime(s) ... print(time.strftime('%c %z %Z', tt))
x = datetime(2010, 11, 7, 5)
s = (x - datetime(1970, 1, 1))//timedelta(seconds=1)
for i in range(-3600, 5000, 1200): ... print_time(s + i) ... Sun Nov 7 00:00:00 2010 -0400 EDT Sun Nov 7 00:20:00 2010 -0400 EDT Sun Nov 7 00:40:00 2010 -0400 EDT Sun Nov 7 01:00:00 2010 -0400 EDT Sun Nov 7 01:20:00 2010 -0400 EDT Sun Nov 7 01:40:00 2010 -0400 EDT Sun Nov 7 01:00:00 2010 -0500 EST Sun Nov 7 01:20:00 2010 -0500 EST
However, neither Local nor Eastern tzinfo instance is capable of reproducing this sequence:
for i in range(-3600, 5000, 1200): ... print(datetime.fromtimestamp(s + i, Eastern).strftime('%c %z %Z'))
Sun Nov 7 00:00:00 2010 -0400 EDT Sun Nov 7 00:20:00 2010 -0400 EDT Sun Nov 7 00:40:00 2010 -0400 EDT Sun Nov 7 01:00:00 2010 -0500 EST Sun Nov 7 01:20:00 2010 -0500 EST Sun Nov 7 01:40:00 2010 -0500 EST Sun Nov 7 01:00:00 2010 -0500 EST Sun Nov 7 01:20:00 2010 -0500 EST
for i in range(-3600, 5000, 1200): ... print(datetime.fromtimestamp(s + i, Local).strftime('%c %z %Z'))
Sun Nov 7 00:00:00 2010 -0400 EDT
Sun Nov 7 00:20:00 2010 -0400 EDT
Sun Nov 7 00:40:00 2010 -0400 EDT
Sun Nov 7 01:00:00 2010 -0400 EDT
Sun Nov 7 01:20:00 2010 -0400 EDT
Sun Nov 7 01:40:00 2010 -0400 EDT
Sun Nov 7 02:00:00 2010 -0500 EST
Sun Nov 7 02:20:00 2010 -0500 EST
----------
_______________________________________
Python tracker
Alexander Belopolsky
x = datetime(2010, 11, 7, 5) s = (x - datetime(1970, 1, 1))//timedelta(seconds=1) for i in range(-3600, 5000, 3600): ... datetime.fromtimestamp(s + i, Local) ... datetime.datetime(2010, 11, 7, 0, 0, tzinfo=EST/EDT) datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST/EDT) datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST/EDT)
which is correct and consistent with Easter timezone:
for i in range(-3600, 5000, 3600): ... datetime.fromtimestamp(s + i, Eastern) ... datetime.datetime(2010, 11, 7, 0, 0, tzinfo=Eastern) datetime.datetime(2010, 11, 7, 1, 0, tzinfo=Eastern) datetime.datetime(2010, 11, 7, 1, 0, tzinfo=Eastern)
----------
keywords: +patch
nosy: +mark.dickinson
stage: needs patch -> commit review
type: -> behavior
Added file: http://bugs.python.org/file17892/issue9063.diff
_______________________________________
Python tracker
Changes by Rodrigo Bernardo Pimentel
Alexander Belopolsky
participants (2)
-
Alexander Belopolsky
-
Rodrigo Bernardo Pimentel