Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104837 > unrolled thread
| Started by | Carl Meyer <carl@oddbird.net> |
|---|---|
| First post | 2016-03-14 10:12 -0600 |
| Last post | 2016-03-14 10:12 -0600 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Missing something about timezones Carl Meyer <carl@oddbird.net> - 2016-03-14 10:12 -0600
| From | Carl Meyer <carl@oddbird.net> |
|---|---|
| Date | 2016-03-14 10:12 -0600 |
| Subject | Re: Missing something about timezones |
| Message-ID | <mailman.116.1457974249.12893.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
Hi Skip,
On 03/14/2016 09:32 AM, Skip Montanaro wrote:
> On Mon, Mar 14, 2016 at 10:26 AM, Ian Kelly <ian.g.kelly@gmail.com> 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
Back to top | Article view | comp.lang.python
csiph-web