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


Groups > comp.lang.python > #52797 > unrolled thread

RE: utcoffset v. _utcoffset

Started by"Prasad, Ramit" <ramit.prasad@jpmorgan.com.dmarc.invalid>
First post2013-08-21 20:58 +0000
Last post2013-08-21 20:58 +0000
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.


Contents

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

#52797 — RE: utcoffset v. _utcoffset

From"Prasad, Ramit" <ramit.prasad@jpmorgan.com.dmarc.invalid>
Date2013-08-21 20:58 +0000
SubjectRE: utcoffset v. _utcoffset
Message-ID<mailman.107.1377118749.19984.python-list@python.org>
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.  

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web