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


Groups > comp.lang.python > #52797

RE: utcoffset v. _utcoffset

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ramit.prasad@jpmorgan.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '16,': 0.03; '(python': 0.07; 'attribute': 0.07; 'completeness': 0.07; 'elements.': 0.07; 'skip:" 60': 0.07; 'dst': 0.09; 'received:155': 0.09; 'to:addr:skip': 0.09; 'sfxlen:2': 0.11; 'python': 0.11; "'''": 0.16; '1.5,': 0.16; 'attribute,': 0.16; 'boundaries,': 0.16; 'boundary.': 0.16; 'crosses': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'received:155.180': 0.16; 'received:159': 0.16; 'received:159.53': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'securities,': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.18; 'seems': 0.21; '>>>': 0.22; 'import': 0.22; '(in': 0.22; 'skip': 0.24; 'versions': 0.24; 'skip:" 30': 0.26; 'updating': 0.26; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'correct': 0.29; 'skip:p 30': 0.29; 'newer': 0.30; "i'm": 0.30; 'file': 0.32; 'received:169.254': 0.32; '(most': 0.33; 'mac': 0.33; 'older': 0.33; 'trouble': 0.34; 'skip:d 20': 0.34; 'problem': 0.35; 'but': 0.35; 'accuracy': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'received:169': 0.37; 'to:addr:python-list': 0.38; 'little': 0.38; 'recent': 0.39; 'does': 0.39; 'realize': 0.39; 'to:addr:python.org': 0.39; 'skip:x 10': 0.40; 'even': 0.60; 'most': 0.60; 'information,': 0.61; 'information': 0.63; 'purchase': 0.65; 'subject:. ': 0.67; 'sample': 0.67; 'subject': 0.69; 'home': 0.69; 'legal': 0.71; 'sale': 0.75; 'latest,': 0.84; 'received:169.254.8': 0.84
X-DKIM OpenDKIM Filter v2.1.3 sz1.jpmchase.com r7LKx0XY012810
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1377118741; bh=+4IVyiPS5L19bYDsVytFBx44pKOQFWYRF3stYaXcITc=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:content-transfer-encoding:MIME-Version; b=DK/f0GVfQTVkPij8myiGk1picec8lHf+PJn/9xnYaIkT2KdpVCDxucU+HIn4qGkyL I36+1oY3dVXfp9V8WK92P3/5fE3E+yM+Da3bhRdk2Lm4yzregw2N1ifOD2sgLVG4Gw 4AwBJpguEnJbczj1g4CcFbgA+BjuFdEX7FUhZo+4=
X-AuditID a959dcad-b7f848e000002ba4-00-52152a141ee9
From "Prasad, Ramit" <ramit.prasad@jpmorgan.com.dmarc.invalid>
To Skip Montanaro <skip@python.org>, Python <python-list@python.org>
Subject RE: utcoffset v. _utcoffset
Thread-Topic utcoffset v. _utcoffset
Thread-Index AQHOnpkNs0k14JginU268/vdW7TA1JmgIi0w
Date Wed, 21 Aug 2013 20:58:58 +0000
References <CANc-5UwRWF343mmOeCJhKj6KaU1m4=qGXHrb3PXv1X5_OD-cgA@mail.gmail.com>
In-Reply-To <CANc-5UwRWF343mmOeCJhKj6KaU1m4=qGXHrb3PXv1X5_OD-cgA@mail.gmail.com>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [10.67.79.47]
Content-Type text/plain; charset="us-ascii"
content-transfer-encoding quoted-printable
MIME-Version 1.0
X-DLP-FWD Yes
X-Brightmail-Tracker H4sIAAAAAAAAA+NgFvrCKsWRmVeSWpSXmKPExsUye4uJoK6IlmiQwbJDMhZHWq+xWsy8vIPd gcnjxfw3bAGMUQ2MNol5efkliSWpCimpxcm2Si6Zxck5iZm5qUUKugpeBbn5RemJeXrJ+blK CpkptkomSgoFOYnJqbmpeSW2SokFBal5KUp2XAoYwAaoLDNPITUvOT8lMy/dVskz2F/XwsLU UtdQyS4kI7NYITU3MTNHIWEje8azVt6CeQIVb1acZm5gnMDbxcjJISFgInH47UFWCFtM4sK9 9WxdjFwcQgJHGCX27j7JCOEcZJRYf+A/K4SziVFix9JV7CAtbAKGEsfPPgGzRQRcJba+/8QE YgsLqEismnWfGSKuKvHg1yQmCNtIounuNDCbBSh+YcFlsF5egRCJw8/fAcU5gBYESPx57A8S 5hQIlHj7cA5YCSPQdd9PrQFrZRYQl7j1ZD4TxNUCEkv2nGeGsEUlXj7+B/WNvMSLKS/ZIOp1 JBbs/gRla0ssW/iaGWKtoMTJmU9YINaqSexbbwtiSgjwSWxvq57AKDELybJZSAbNQjJoFpJB CxhZVjFKFuemZxnpFZcV6ZUW62UV5CZnJBan6uWllmxiBCaWlZF31u5gXN5te4hRgINRiYc3 4plIkBBrYllxZe4hRgkOZiUR3sZNGwOFeFMSK6tSi/Lji0pzUosPMVYBg2wis5Rocj4w6eWV xBsam1kYmJoaGlgYGplQRVhJnHdHLneQkEA6MKFmp6YWpBbBLGfi4JRqYGT8r+7+fWv4jMb6 neU/OC+96A7371G/Jv57ndZZEz/bxK8S78uieZ9EH9kxJ6tx5vzGGX+lZM5rdUSZCG35vfjw Mv0qllbmjdOWnFO4t/2RcVdFW+21bVfP7eQsXaJWu+S142HfkMsL9vDwlL8vdghmnHTEbpeD cPVsiVrhxbu/qOj4Xfy4UkGJpTgj0VCLuag4EQA2GCv8hwMAAA==
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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.107.1377118749.19984.python-list@python.org> (permalink)
Lines 71
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1377118749 news.xs4all.nl 15936 [2001:888:2000:d::a6]:57540
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52797

Show key headers only | View raw


Skip Montanaro wrote:
> 
> Consider this little Python script:
> 
> import dateutil.parser
> import pytz
> 
> x = dateutil.parser.parse("2013-08-16 23:00:00+01:00")
> localtz = pytz.timezone("America/Chicago")
> y = localtz.normalize(x)
> 
> When I execute it (Python 2.7.2, dateutil 1.5, pytz 2011h), I get this
> traceback:
> 
> Traceback (most recent call last):
>   File "/home/skipm/tmp/localtzex.py", line 8, in <module>
>     y = localtz.normalize(x)
>   File "/opt/TWWfsw/python27p/lib/python2.7/site-packages/pytz/tzinfo.py",
> line 233, in normalize
>     offset = dt.tzinfo._utcoffset
> AttributeError: 'tzoffset' object has no attribute '_utcoffset'
> 
> Looking at the tzinfo attribute, I see that it has "utcoffset", but
> not "_utcoffset".  I realize those are the latest, most up-to-datest
> versions of all three elements.  I'm having trouble updating dateutil
> and pytz on my Mac at home (stuck on even older versions).  Can
> someone with newer versions of dateutil and pytz see if this problem
> is still present?
> 
> Thx,
> 
> Skip
> --

Using Python 2.6, dateutil 1.5, pytz 2013b


Snipped from the documentation of pytz via help(localtz.normalize)
''' 
    Correct the timezone information on the given datetime
    
    If date arithmetic crosses DST boundaries, the tzinfo
    is not magically adjusted. This method normalizes the
    tzinfo to the correct one.
'''

Going from +1 to +6 will not cross the DST boundary.

The documentation for localtz.normalize (in pytz 2013b) has a sample 
of what to do if it does cross DST which seems to boil down to using 
datetime.astimezone() and then localtz.normalize() if your date 
arithmetic crosses DST.

>>> import dateutil.parser
>>> import pytz
>>> x = dateutil.parser.parse("2013-08-16 23:00:00+01:00")
>>> localtz = pytz.timezone("America/Chicago")
>>> x.astimezone( localtz )
datetime.datetime(2013, 8, 16, 17, 0, tzinfo=<DstTzInfo 'America/Chicago' CDT-1 day, 19:00:00 DST>)


~Ramit



This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email.  

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


Thread

RE: utcoffset v. _utcoffset "Prasad, Ramit" <ramit.prasad@jpmorgan.com.dmarc.invalid> - 2013-08-21 20:58 +0000

csiph-web