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


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

Missing something about timezones

Started bySkip Montanaro <skip.montanaro@gmail.com>
First post2016-03-14 10:19 -0500
Last post2016-03-16 02:29 -0700
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Missing something about timezones Skip Montanaro <skip.montanaro@gmail.com> - 2016-03-14 10:19 -0500
    Re: Missing something about timezones Peter Pearson <pkpearson@nowhere.invalid> - 2016-03-16 00:12 +0000
    Re: Missing something about timezones wxjmfauth@gmail.com - 2016-03-16 02:29 -0700

#104821 — Missing something about timezones

FromSkip Montanaro <skip.montanaro@gmail.com>
Date2016-03-14 10:19 -0500
SubjectMissing something about timezones
Message-ID<mailman.103.1457968773.12893.python-list@python.org>
Is this correct (today, with Daylight Savings in effect)?

>>> import pytz
>>> i.timezone
'America/Chicago'
>>> pytz.timezone(i.timezone)
<DstTzInfo 'America/Chicago' CST-1 day, 18:00:00 STD>
>>> ot
datetime.datetime(2016, 3, 14, 9, 30, tzinfo=<DstTzInfo
'America/New_York' EDT-1 day, 20:00:00 DST>)
>>> ot.tzinfo
<DstTzInfo 'America/New_York' EDT-1 day, 20:00:00 DST>

Shouldn't the America/Chicago timezone reflect DST?

Thx,

Skip

[toc] | [next] | [standalone]


#104971

FromPeter Pearson <pkpearson@nowhere.invalid>
Date2016-03-16 00:12 +0000
Message-ID<dkrmncFhk2uU1@mid.individual.net>
In reply to#104821
On Mon, 14 Mar 2016 10:19:23 -0500, Skip Montanaro wrote:
> Is this correct (today, with Daylight Savings in effect)?
>
>>>> import pytz
>>>> i.timezone
> 'America/Chicago'
>>>> pytz.timezone(i.timezone)
><DstTzInfo 'America/Chicago' CST-1 day, 18:00:00 STD>
>>>> ot
> datetime.datetime(2016, 3, 14, 9, 30, tzinfo=<DstTzInfo
> 'America/New_York' EDT-1 day, 20:00:00 DST>)
>>>> ot.tzinfo
><DstTzInfo 'America/New_York' EDT-1 day, 20:00:00 DST>


I've stubbed my toe many times on timezones and DST.  Here are
some notes I've accumulated:

 * datetime.datetime(..., tzinfo=tz) doesn't work right for timezones
   that involve daylight-saving time, but nobody gets around to fixing
   it because it's written in C; and

 * knowing this, the creators of pytz thoughtfully furnished a
   workaround, in the form of the "localize" method of a pytz.timezone
   object:

    >>> loc_dt = eastern.localize(datetime(2002, 10, 27, 6, 0, 0)) 
    >>> print(loc_dt.strftime(fmt))
    2002-10-27 06:00:00 EST-0500


$ cat temp2.py
from datetime import datetime
from pytz import timezone

print(str(datetime(2015, 1, 31, 12, tzinfo=timezone("US/Pacific"))))
print(str(datetime(2015, 7, 31, 12, tzinfo=timezone("US/Pacific"))))

print(str(timezone("US/Pacific").localize(datetime(2015, 1, 31, 12))))
print(str(timezone("US/Pacific").localize(datetime(2015, 7, 31, 12))))

$ python temp2.py
2015-01-31 12:00:00-08:00
2015-07-31 12:00:00-08:00 <- wrong
2015-01-31 12:00:00-08:00
2015-07-31 12:00:00-07:00 <- right
$

Good luck!

-- 
To email me, substitute nowhere->runbox, invalid->com.

[toc] | [prev] | [next] | [standalone]


#104995

Fromwxjmfauth@gmail.com
Date2016-03-16 02:29 -0700
Message-ID<83a6ae37-0dca-4207-920b-e2c8250fa011@googlegroups.com>
In reply to#104821
Time zones ?


1) One more reason to not recommend Python.
2) A very nice example showing how Python 3 is
buggy.

Sad reality, but reality.

jmf

[toc] | [prev] | [standalone]


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


csiph-web