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


Groups > comp.lang.python > #87910

Re: Daylight savings time question

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <gherron@digipen.edu>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.078
X-Spam-Evidence '*H*': 0.84; '*S*': 0.00; 'dan': 0.09; 'hour.': 0.09; 'main()': 0.09; 'subject:question': 0.10; 'def': 0.12; 'jumps': 0.16; 'main():': 0.16; 'numerically': 0.16; 'skip:0 40': 0.16; 'wrote:': 0.18; 'library': 0.18; 'module': 0.19; 'skip:f 30': 0.19; 'later': 0.20; 'import': 0.22; 'header:User-Agent:1': 0.23; 'spring': 0.24; 'header:In-Reply-To:1': 0.27; 'rest': 0.29; 'skip:p 30': 0.29; '(which': 0.31; 'getting': 0.31; 'clock': 0.31; 'gary': 0.31; 'this.': 0.32; 'thanks!': 0.32; 'skip:# 10': 0.33; 'subject:time': 0.33; 'skip:d 20': 0.34; "i'd": 0.34; 'there': 0.35; 'pacific': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'march': 0.61; "you've": 0.63; 'love': 0.65; 'forward': 0.65; 'charset:windows-1252': 0.65; 'hours': 0.66; 'institute': 0.72; 'received:204': 0.75; 'dr.': 0.77; 'savings': 0.81; '2015': 0.84; 'back?': 0.84; 'skip:w 60': 0.84; 'subject:savings': 0.84
Date Tue, 24 Mar 2015 15:34:25 -0700
From Gary Herron <gherron@digipen.edu>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Daylight savings time question
References <CAGGBd_pFpemgisb-2WFQvu8MehQfHhUJ7=n9CyYFxjj56xOV_g@mail.gmail.com>
In-Reply-To <CAGGBd_pFpemgisb-2WFQvu8MehQfHhUJ7=n9CyYFxjj56xOV_g@mail.gmail.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.19
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.121.1427236471.10327.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1427236471 news.xs4all.nl 2910 [2001:888:2000:d::a6]:59242
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:87910

Show key headers only | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Daylight savings time question Gary Herron <gherron@digipen.edu> - 2015-03-24 15:34 -0700

csiph-web