Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104821 > unrolled thread
| Started by | Skip Montanaro <skip.montanaro@gmail.com> |
|---|---|
| First post | 2016-03-14 10:19 -0500 |
| Last post | 2016-03-16 02:29 -0700 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
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
| From | Skip Montanaro <skip.montanaro@gmail.com> |
|---|---|
| Date | 2016-03-14 10:19 -0500 |
| Subject | Missing 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]
| From | Peter Pearson <pkpearson@nowhere.invalid> |
|---|---|
| Date | 2016-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]
| From | wxjmfauth@gmail.com |
|---|---|
| Date | 2016-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