Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87910 > unrolled thread
| Started by | Gary Herron <gherron@digipen.edu> |
|---|---|
| First post | 2015-03-24 15:34 -0700 |
| Last post | 2015-03-24 15:34 -0700 |
| 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.
Re: Daylight savings time question Gary Herron <gherron@digipen.edu> - 2015-03-24 15:34 -0700
| From | Gary Herron <gherron@digipen.edu> |
|---|---|
| Date | 2015-03-24 15:34 -0700 |
| Subject | Re: Daylight savings time question |
| Message-ID | <mailman.121.1427236471.10327.python-list@python.org> |
On 03/24/2015 03:24 PM, Dan Stromberg wrote:
> Is there a way of "adding" 4 hours and getting a jump of 5 hours on
> March 8th, 2015 (due to Daylight Savings Time), without hardcoding
> when to spring forward and when to fall back? I'd love it if there's
> some library that'll do this for me.
>
> #!/usr/bin/python
>
> import pytz
> import datetime
>
> def main():
> # On 2015-03-08, 2:00 AM to 2:59AM Pacific time does not exist -
> the clock jumps forward an hour.
> weird_naive_datetime = datetime.datetime(2015, 3, 8, 1, 0,
> 0).replace(tzinfo=pytz.timezone('US/Pacific'))
> weird_tz_aware_datetime =
> weird_naive_datetime.replace(tzinfo=pytz.timezone('US/Pacific'))
> print(weird_tz_aware_datetime)
> four_hours=datetime.timedelta(hours=4)
> print('Four hours later is:')
> print(weird_tz_aware_datetime + four_hours)
> print('...but I want numerically 5 hours later, because of
> Daylight Savings Time')
>
> main()
>
>
> Thanks!
The pyzt module (which you've imported) has lots to say about this. Look
at its procedures "localize' and 'normalize' and all the rest of the
pyzt documentation.
--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418
Back to top | Article view | comp.lang.python
csiph-web