Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #104837

Re: Missing something about timezones

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Carl Meyer <carl@oddbird.net>
Newsgroups comp.lang.python
Subject Re: Missing something about timezones
Date Mon, 14 Mar 2016 10:12:24 -0600
Lines 63
Message-ID <mailman.116.1457974249.12893.python-list@python.org> (permalink)
References <CANc-5UxYPyj85EZfOwGuJarBNj=Ob4mdu7A3Vt4rL8qJhTi+8A@mail.gmail.com> <CALwzidmkEkJzmDipPHddfjwx0ggxD=9Vg-csGaTY0+KUojL1eg@mail.gmail.com> <CANc-5UxK6uAPFVX50ZUCjpsqJZRPao1Z+kv5kFKTr0cVXrb03Q@mail.gmail.com>
Mime-Version 1.0
Content-Type multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="OI7qkuSh4vNObvFTTITVJ3g0U4ksAloNP"
X-Trace news.uni-berlin.de QqZaF3WUsIbjUDz0mmGeJgGv5uyCPC5tEmqkwZoSdTFw==
Return-Path <carl@oddbird.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.011
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'that?': 0.05; 'dst': 0.07; 'skip:` 30': 0.09; '10:26': 0.16; '2016': 0.16; 'filename:fname piece:signature': 0.16; 'from:addr:carl': 0.16; 'received:173.255': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'skip': 0.18; 'thanks.': 0.18; '>>>': 0.20; 'chicago': 0.22; 'implicit': 0.22; 'am,': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'header:User-Agent:1': 0.26; '14,': 0.27; 'reflect': 0.27; "skip:' 10": 0.28; '13,': 0.29; 'asked': 0.29; 'relative': 0.30; 'supposed': 0.31; 'correctly': 0.34; 'handle': 0.34; 'skip:d 20': 0.34; 'skip:p 30': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'thought': 0.37; 'why': 0.39; 'does': 0.39; "didn't": 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; "you'll": 0.61; 'charset:windows-1252': 0.62; 'mar': 0.65; 'savings.': 0.66; 'account': 0.66; '09:32': 0.84
X-Enigmail-Draft-Status N1110
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0
In-Reply-To <CANc-5UxK6uAPFVX50ZUCjpsqJZRPao1Z+kv5kFKTr0cVXrb03Q@mail.gmail.com>
X-Spam-Status No (score -1.0): ALL_TRUSTED=-1
X-Spam-Bar -
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:104837

Show key headers only | View raw


[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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Missing something about timezones Carl Meyer <carl@oddbird.net> - 2016-03-14 10:12 -0600

csiph-web