neglecting daylight savings

Discussion in 'Python' started by Neil Berg, Nov 12, 2010.

  1. Neil Berg

    Neil Berg Guest

    Hi Python community,

    I am trying to convert UTC to PST and want to neglect daylight savings even for the days that are in PDT, not PST. I simply want every UTC date to be pushed back by 8 hours and not worry about the days when the difference is really -7 due to daylight savings. I have written a function called utc_to_local (pasted below) that reads in the UTC year, month, day, and hour from a main code and returns that value in local standard time. The problem is that I can't figure out how to "turn off" the automatic daylight savings switch that appears be built in to somewhere.

    Here is some sample output showing the daylight savings switch on April 2, 1995 at 2am local time, which I would like to override.

    1995-04-02 08 UTC = 1995-04-02 00 PST
    1995-04-02 09 UTC = 1995-04-02 01 PST
    1995-04-02 10 UTC = 1995-04-02 03 PDT
    1995-04-02 11 UTC = 1995-04-02 04 PDT

    I want the third line of the output to read "1995-04-02 02" PST, the fourth to read "1995-04-02 03", etc.
    ___________________________

    from datetime import datetime
    from pytz import timezone
    import pytz

    def utc_to_local(yr,mo,dy,hr):
    fmt = '%Y-%m-%d %H %Z'
    utc = pytz.utc
    pacific = pytz.timezone("America/Los_Angeles")
    utc_dt = datetime(yr,mo,dy,hr, tzinfo=utc)
    loc_dt = utc_dt.astimezone(pacific) # local date YY-MM-DD HR TZ
    print utc_dt.strftime(fmt), "=", loc_dt.strftime(fmt)
    loc_y = loc_dt.year # local year
    loc_m = loc_dt.month # local month
    loc_d = loc_dt.day # local day
    loc_h = loc_dt.hour # local hour

    return loc_y, loc_m, loc_d, loc_h
    _____________________________
    Python 2.6
    Mac OS X 10.6.4
    _____________________________
    Any help is much appreciated.

    Thank you in advance,
    Neil Berg
    Neil Berg, Nov 12, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Ternier
    Replies:
    1
    Views:
    1,461
    Ryan Ternier
    Oct 14, 2005
  2. Svante Nicholas Arvedahl

    Daylight savings problem

    Svante Nicholas Arvedahl, Oct 20, 2003, in forum: Java
    Replies:
    9
    Views:
    4,948
    Svante Nicholas Arvedahl
    Oct 24, 2003
  3. Hariharan.A
    Replies:
    0
    Views:
    1,722
    Hariharan.A
    Feb 25, 2004
  4. lordy
    Replies:
    3
    Views:
    1,891
    lordy
    Jul 14, 2006
  5. js
    Replies:
    1
    Views:
    779
Loading...

Share This Page