finally fix the DST handling properly using pytz

This commit is contained in:
steffen123 2010-07-29 16:18:05 +02:00
parent 5721b5b23c
commit 792a2aec4f

View File

@ -26,8 +26,11 @@ import codecs
from decimal import Decimal from decimal import Decimal
import operator import operator
from xml.dom.minidom import Node from xml.dom.minidom import Node
import time import time
import datetime import datetime
from pytz import timezone
import pytz
import logging import logging
# logging has been set up in fpdb.py or HUD_main.py, use their settings: # logging has been set up in fpdb.py or HUD_main.py, use their settings:
@ -497,23 +500,24 @@ or None if we fail to get the info """
@staticmethod @staticmethod
def changeTimezone(time, givenTimezone, wantedTimezone): def changeTimezone(time, givenTimezone, wantedTimezone):
offest = datetime.timedelta(hours=0) #print "raw time:",time, "given TZ:", givenTimezone
if givenTimezone=="ET" and wantedTimezone=="UTC": if wantedTimezone=="UTC":
# approximate rules for ET daylight savings time: wantedTimezone = pytz.utc
if ( time.month == 12 # all of Dec else:
or (time.month == 11 and time.day > 4) # and most of November raise Error #TODO raise appropriate error
or time.month < 3 # and all of Jan/Feb
or (time.month == 3 and time.day < 11) ): # and 1st 10 days of March if givenTimezone=="ET":
offset = datetime.timedelta(hours=5) # are EST: assume 5 hour offset (ET without daylight saving) givenTimezone = timezone('US/Eastern')
else: elif givenTimezone=="CET":
offset = datetime.timedelta(hours=4) # rest is EDT: assume 4 hour offset (ET with daylight saving) givenTimezone = timezone('Europe/Berlin')
#print " tz = %s start = %s" % (tz, str(hand.starttime)) #Note: Daylight Saving Time is standardised across the EU so this should be fine
elif givenTimezone=="CET" and wantedTimezone=="UTC": else:
offset = datetime.timedelta(hours=1) raise Error #TODO raise appropriate error
# adjust time into UTC: localisedTime = givenTimezone.localize(time)
time = time + offset utcTime = localisedTime.astimezone(wantedTimezone)
return time #print "utcTime:",utcTime
return utcTime
#end @staticmethod def changeTimezone #end @staticmethod def changeTimezone
@staticmethod @staticmethod