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


Groups > comp.lang.python > #87909

Daylight savings time question

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <drsalists@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.053
X-Spam-Evidence '*H*': 0.89; '*S*': 0.00; '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; 'to:name:python list': 0.16; 'library': 0.18; 'skip:f 30': 0.19; 'later': 0.20; 'import': 0.22; 'spring': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'skip:p 30': 0.29; 'message- id:@mail.gmail.com': 0.30; 'getting': 0.31; 'clock': 0.31; 'thanks!': 0.32; 'skip:# 10': 0.33; 'subject:time': 0.33; 'skip:d 20': 0.34; "i'd": 0.34; 'received:google.com': 0.35; 'there': 0.35; 'pacific': 0.36; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'march': 0.61; 'love': 0.65; 'forward': 0.65; 'hours': 0.66; 'savings': 0.81; '2015': 0.84; 'back?': 0.84; 'skip:w 60': 0.84; 'subject:savings': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=PY51EeX/muffVNNDYFwg00kSmOUAiBfsOW46POe0ZQU=; b=gW8UmUxCAG3+pu6aMVPlJB8+6vQpcCIsxJGzSgbtrhYKhulIzRxIELfX7YlOWcugGi sLFVhQYK2BJQl3Sxwub6u3XcezDgG7U5hLLZOS0KuIcSMZnYHHEpsVWylAeMLmCwJtr7 XjQ5KQ1xpGqOe1Fjq+KoxpimbjNWEPHbhJAHaIXhTNyb+nRX5IJFDh5+TvGGmshAD3ee qR8KMOGPY9YYr/ESVVBETFMJHgnnMVuWvemh+Uc6q5rNRJNVE2cbpo4LtXM9xY/y56lg FMNYNv5PZiDy5ujXnCQ+vQHacmcSL0DnwjRjPIBTOvSiJ7yp2e113N3UrjlR5HDQbhNg 0CWA==
MIME-Version 1.0
X-Received by 10.152.37.228 with SMTP id b4mr5501454lak.111.1427235896499; Tue, 24 Mar 2015 15:24:56 -0700 (PDT)
Date Tue, 24 Mar 2015 15:24:56 -0700
Subject Daylight savings time question
From Dan Stromberg <drsalists@gmail.com>
To Python List <python-list@python.org>
Cc dan_stromberg@intuit.com
Content-Type text/plain; charset=UTF-8
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.120.1427235904.10327.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1427235904 news.xs4all.nl 2857 [2001:888:2000:d::a6]:55252
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:87909

Show key headers only | View raw


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!

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Daylight savings time question Dan Stromberg <drsalists@gmail.com> - 2015-03-24 15:24 -0700

csiph-web