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


Groups > comp.lang.python > #104834

Re: Missing something about timezones

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Missing something about timezones
Date Mon, 14 Mar 2016 10:20:55 -0600
Lines 33
Message-ID <mailman.113.1457972497.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 text/plain; charset=UTF-8
X-Trace news.uni-berlin.de UTgywVEKHEgOU3FRy/YgsAUikVGeaUIRCqvzhVCO0Cew==
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '16,': 0.03; 'received:209.85.223': 0.03; 'that?': 0.05; '40,': 0.09; 'incorrect': 0.09; '10:26': 0.16; '2016': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'should.': 0.16; 'wrote:': 0.16; 'skip': 0.18; 'thanks.': 0.18; '>>>': 0.20; 'chicago': 0.22; 'am,': 0.23; "haven't": 0.24; 'import': 0.24; 'header:In-Reply- To:1': 0.24; 'mon,': 0.24; 'example': 0.26; 'message- id:@mail.gmail.com': 0.27; '14,': 0.27; 'specifically': 0.28; 'asked': 0.29; "i'm": 0.30; 'relative': 0.30; 'supposed': 0.31; 'skip:d 20': 0.34; 'received:google.com': 0.35; 'skip:p 30': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'thought': 0.37; 'received:209': 0.38; 'why': 0.39; "didn't": 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'mar': 0.65; 'savings.': 0.66; 'account': 0.66; 'demonstrates': 0.84; 'to:name:python': 0.84; 'technically': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=VCf6bEX//8zyabii+eTnAdDJqAj7MyxG4i8BZ5DSs0Q=; b=xopnWMfUkvGo37NNKCVkAOn10jhmmYBleQwfNY0+wqUCn742v2XIq88WT+mkpsR4zY gKRLuu/OKnLMZtCd8Ue8pUaB1l6D1vq40fRNud1yP39CY/eEU8L25bf9TAJo1U+Qe5by R2Ke0VD6VYXjHvQ1NVQlmFex79LoiN+9GMb2PymdiUrHV2RRs7ddvQ23tB6JPdeyt8dr ZeIE4krJwaTjN9XwqXDr3fvAWQuyRlW9TR9xypPHEVzsHcjVqhwCcAjrM/Gp5XTLTptV TQmsoTAyAe1ffJh1bt5zqy5sp+Gu6GO2g5JqPseYznjw9XsuPtPUQgjvfi4dH7vCAyMu REEw==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=VCf6bEX//8zyabii+eTnAdDJqAj7MyxG4i8BZ5DSs0Q=; b=JwSxfL76zQNCPkHKKUljW2AI17DoM/c23tgbUQOaKIUbQVDKBI1HRgMAmWxG+A1hSO GUCmE0aqHiHYoZn2A8gqLx11JK/wh0erk+Rv4zgHgkKeIxs3wySvAeg1JJJWqpZE8U0g r6SsHT75z5aGjwxMIqgK/jxMsvRqt2gUUDk8WZGzN1xeJMt+flTAceKNNN1lJyyGmJd1 z7zH/FJITc5aj8EJ8gIbiwfc8TKdmc2xKw427XlrpjUirrAKT4+7MBLBMWfqywB9nTO7 RICYo4R4mvmPVo9R3qhgBD6f7hxizYoHVi0pTUuJWuAqiskYaTXycyu9dCl3g8drIr/G yxzg==
X-Gm-Message-State AD7BkJIakUe+cEksXfo1DLaOCvEsP+kmUBUt+MoUB5wZDhFYCRtAhT39b2z2poem0l6LK1tuSDLFwvLUrm3lUg==
X-Received by 10.107.11.148 with SMTP id 20mr16133439iol.111.1457972494990; Mon, 14 Mar 2016 09:21:34 -0700 (PDT)
In-Reply-To <CANc-5UxK6uAPFVX50ZUCjpsqJZRPao1Z+kv5kFKTr0cVXrb03Q@mail.gmail.com>
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:104834

Show key headers only | View raw


On Mon, Mar 14, 2016 at 9:32 AM, Skip Montanaro
<skip.montanaro@gmail.com> 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?

Use the timezone to localize a specific time, and then if it's
specifically the timezone that you're interested in, you can get it
from the datetime.

>>> from datetime import datetime
>>> import pytz
>>> tz = pytz.timezone('America/Chicago')
>>> tz
<DstTzInfo 'America/Chicago' CST-1 day, 18:00:00 STD>
>>> dt = datetime.now()
>>> dt
datetime.datetime(2016, 3, 14, 10, 16, 40, 404608)
>>> loc_dt = tz.localize(dt)
>>> loc_dt
datetime.datetime(2016, 3, 14, 10, 16, 40, 404608, tzinfo=<DstTzInfo
'America/Chicago' CDT-1 day, 19:00:00 DST>)

Note that the above example is technically incorrect since
datetime.now() returns local time and I'm not in the Chicago timezone,
but it demonstrates the process.

Also, if you haven't already read the pytz documentation, you should.
http://pythonhosted.org/pytz/

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Missing something about timezones Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-14 10:20 -0600

csiph-web