This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients
Date 2006-09-07.17:11:53
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=31435

`tzinfo` is the name of a datetime data attribute, and the
same name (i.e., "tzinfo") is generally used for arguments
that mindlessly attach a subclass of the `tzinfo` class to
an object as the value of its `tzinfo` data attribute.  The
datetime constructor is an example of that.  `tz` is
generally used when the time zone info is /actively
applied/, as now() does.

In contrast, the datetime constructor never makes any
attempt at conversion; if a tzinfo argument is passed, it's
merely tacked on to the datetime object.

Beyond that, I have no idea why the pytz class passed to
now() isn't showing up as the resulting datetime object's
tzinfo member.  For example, that's not what happens if you
try this in the Python sandbox "datetime" directory:

>>> from US import Eastern
>>> from datetime import datetime
>>> now = datetime.now(Eastern)
>>> now
datetime.datetime(2006, 9, 7, 12, 49, 48, 430000,
tzinfo=<US.USTimeZone object at 0x009E89B0>)
>>> t2 = datetime(2006, 9, 7, 12, 49, 48, 430000,
tzinfo=Eastern)
>>> t2
datetime.datetime(2006, 9, 7, 12, 49, 48, 430000,
tzinfo=<US.USTimeZone object at 0x009E89B0>)
>>> now.tzinfo == Eastern
True
>>> t2.tzinfo == Eastern
True
>>> t2.tzinfo is now.tzinfo is Eastern
True

I expect the pytz developers could shed light on that. 
datetime.now(tz) with `tz` not None first mindlessly
constructs a datetime object (let's call it `self`) based on
current (UTC) time with tz attached as the value of its
`tzinfo` data attribute, and then returns the result of invoking

tz.fromutc(self)

So if pytz overrides the default `fromutc()` implementation
in its tzinfo subclasses, you'll get back whatever they
decided to return from it.  No code in Python "makes an
off-by-one-hour copy" here.

In short, I believe your primary question here is about how
pytz works, and I can't answer that.  IIRC, pytz does fancy
stuff trying to avoid the 1-hour ambiguities at DST
transition times, and I wouldn't be surprised if, toward
that end, they have multiple internal tzinfo subclasses for
each "conceptual" time zone.
History
Date User Action Args
2007-08-23 14:42:34adminlinkissue1553577 messages
2007-08-23 14:42:34admincreate