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


Groups > comp.lang.python > #64952

UTC "timezone" causing brain explosions

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <skip.montanaro@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.045
X-Spam-Evidence '*H*': 0.91; '*S*': 0.00; '21,': 0.07; 'correct,': 0.09; '39,': 0.16; 'from:addr:pobox.com': 0.16; 'from:addr:skip': 0.16; 'utc': 0.16; 'utc.': 0.16; 'values:': 0.16; 'sender:addr:gmail.com': 0.17; 'variable': 0.18; '>>>': 0.22; 'import': 0.22; 'skip': 0.24; 'earlier': 0.24; 'looks': 0.24; '15,': 0.26; 'skip:p 30': 0.29; 'message-id:@mail.gmail.com': 0.30; 'object.': 0.31; 'call.': 0.33; 'trouble': 0.34; 'skip:d 20': 0.34; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'chair': 0.36; 'right?': 0.36; 'to:addr:python-list': 0.38; 'does': 0.39; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'skip:u 10': 0.60; 'happen': 0.63; 'us:': 0.65; 'city': 0.66; 'chicago,': 0.68; 'good,': 0.91; 'sitting': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=fdNq4MtMml8hRnMTXLnBuYHTM143dPVNSiOUet9HyhQ=; b=pdD9kvx+xvhjcE8WEhrX8bAcp6Wv8ll7fCHoBQvNueXRDiT/bSp7cFgPgPYF+ShDsR CqeOGrppL9RtnTEQ/UQJ8uaCGbk+GCLWCo5cUuGJ9834LQoci6G9uBy/ZoXAEBOLMA2E UpOVSL8ysCzvPfU7Z1FsxowVnVW7azjxxa/uI9+PC2n445jtA8qH1RHu1kvNsZ3NCqGR nMz6HxPgYt+F58A/l91WZDZycT+G8bBalEX63QsxE81+MJdg+8AGvDLEc9WIVGNlzXih hge51aa2ovBOrIE3OXLuV83hfeFYfIRq8DObKBVNjdTS1kXI0kLRMjlLLNN0H+mKrgaA nUHQ==
MIME-Version 1.0
X-Received by 10.50.114.168 with SMTP id jh8mr10902418igb.6.1391032325201; Wed, 29 Jan 2014 13:52:05 -0800 (PST)
Sender skip.montanaro@gmail.com
Date Wed, 29 Jan 2014 15:52:05 -0600
X-Google-Sender-Auth qBvhNArcukFFFnbBY7LecSY6B74
Subject UTC "timezone" causing brain explosions
From Skip Montanaro <skip@pobox.com>
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.6098.1391032788.18130.python-list@python.org> (permalink)
Lines 47
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391032788 news.xs4all.nl 2880 [2001:888:2000:d::a6]:33435
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64952

Show key headers only | View raw


Following up on my earlier note about UTC v. GMT, I am having some
trouble grokking attempts to convert a datetime into UTC. Consider
these three values:

>>> import pytz
>>> UTC = pytz.timezone("UTC")
>>> UTC
<UTC>
>>> LOCAL_TZ = pytz.timezone("America/Chicago")
>>> LOCAL_TZ
<DstTzInfo 'America/Chicago' CST-1 day, 18:00:00 STD>
>>> now = datetime.datetime.now()
>>> now
datetime.datetime(2014, 1, 29, 15, 39, 35, 263666)

All well and good, right? The variable "now" is a naive datetime
object. I happen to be sitting in a chair in the city of Chicago, so
let's call it what it is, a datetime in the America/Chicago timezone:

>>> s = LOCAL_TZ.localize(now)
>>> s
datetime.datetime(2014, 1, 29, 15, 39, 35, 263666, tzinfo=<DstTzInfo
'America/Chicago' CST-1 day, 18:00:00 STD>)

That looks good to me. Now, let's normalize it to UTC:

>>> t = UTC.normalize(s)
>>> t
datetime.datetime(2014, 1, 29, 15, 39, 35, 263666, tzinfo=<UTC>)
>>> t.hour
15

WTF? Why isn't the t.hour == 21?

Okay, let's see what GMT does for us:

>>> GMT = pytz.timezone("GMT")
>>> u = GMT.normalize(s)
>>> u
datetime.datetime(2014, 1, 29, 21, 39, 35, 263666, tzinfo=<StaticTzInfo 'GMT'>)
>>> u.hour
21

That looks correct, but I don't understand why I don't get hour==21
out of the UTC.normalize call. It's like it's a no-op.

Skip

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


Thread

UTC "timezone" causing brain explosions Skip Montanaro <skip@pobox.com> - 2014-01-29 15:52 -0600

csiph-web