Hi Skip, On 03/14/2016 09:32 AM, Skip Montanaro wrote: > On Mon, Mar 14, 2016 at 10:26 AM, Ian Kelly <[email protected]> wrote: >> Why should it? You only asked pytz for the Chicago timezone. You >> didn't ask for it relative to any specific time. > > Thanks. I thought using America/Chicago was supposed to automagically > take into account transitions into and out of Daylight Savings. Is > there some way to get that?
Yes, pytz can handle DST correctly automatically when you give it
'America/Chicago', but until you apply that timezone to a particular
datetime, there is no DST to handle. There is no implicit assumption of
"today" when you do `pytz.timezone('America/Chicago').
If you apply the timezone to a particular datetime, you'll see that it
does reflect DST correctly:
>>> import datetime, pytz
>>> tz = pytz.timezone('America/Chicago')
>>> tz
<DstTzInfo 'America/Chicago' LMT-1 day, 18:09:00 STD>
>>> import datetime
>>> dt = datetime.datetime.now()
>>> dtl = tz.localize(dt)
>>> dtl
datetime.datetime(2016, 3, 14, 10, 11, 13, 514375, tzinfo=<DstTzInfo
'America/Chicago' CDT-1 day, 19:00:00 DST>)
Carl
signature.asc
Description: OpenPGP digital signature
-- https://mail.python.org/mailman/listinfo/python-list
