REFACTOR: move timezone changing method to HHC so it can used by other parsers

This commit is contained in:
steffen123 2010-07-13 20:37:06 +02:00
parent b8968591c5
commit 522a745ead
3 changed files with 20 additions and 17 deletions

View File

@ -494,6 +494,23 @@ or None if we fail to get the info """
def getTourney(self):
return self.tourney
@staticmethod
def changeTimezone(time, givenTimezone, wantedTimezone):
if givenTimezone=="ET" and wantedTimezone=="UTC":
# approximate rules for ET daylight savings time:
if ( time.month == 12 # all of Dec
or (time.month == 11 and time.day > 4) # and most of November
or time.month < 3 # and all of Jan/Feb
or (time.month == 3 and time.day < 11) ): # and 1st 10 days of March
offset = datetime.timedelta(hours=5) # are EST: assume 5 hour offset (ET without daylight saving)
else:
offset = datetime.timedelta(hours=4) # rest is EDT: assume 4 hour offset (ET with daylight saving)
# adjust time into UTC:
time = time + offset
#print " tz = %s start = %s" % (tz, str(hand.starttime))
return time
#end @staticmethod def changeTimezone
@staticmethod
def getTableTitleRe(type, table_name=None, tournament = None, table_number=None):

View File

@ -21,6 +21,7 @@ from decimal import Decimal
import datetime
from Exceptions import FpdbParseError
from HandHistoryConverter import *
import PokerStarsToFpdb
from TourneySummary import *
@ -106,7 +107,7 @@ class PokerStarsSummary(TourneySummary):
result=result.groupdict()
datetimestr = "%s/%s/%s %s:%s:%s" % (result['Y'], result['M'],result['D'],result['H'],result['MIN'],result['S'])
self.startTime= datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S") # also timezone at end, e.g. " ET"
self.startTime = PokerStarsToFpdb.removeET(self.startTime)
self.startTime = HandHistoryConverter.changeTimezone(self.startTime, "ET", "UTC")
currentLine+=1
result=self.re_DateTime.search(lines[currentLine])

View File

@ -26,21 +26,6 @@ from decimal import Decimal
# PokerStars HH Format
def removeET(time):
# approximate rules for ET daylight savings time:
if ( time.month == 12 # all of Dec
or (time.month == 11 and time.day > 4) # and most of November
or time.month < 3 # and all of Jan/Feb
or (time.month == 3 and time.day < 11) ): # and 1st 10 days of March
offset = datetime.timedelta(hours=5) # are EST: assume 5 hour offset (ET without daylight saving)
else:
offset = datetime.timedelta(hours=4) # rest is EDT: assume 4 hour offset (ET with daylight saving)
# adjust time into UTC:
time = time + offset
#print " tz = %s start = %s" % (tz, str(hand.starttime))
return time
#end def removeET
class PokerStars(HandHistoryConverter):
# Class Variables
@ -244,7 +229,7 @@ class PokerStars(HandHistoryConverter):
#tz = a.group('TZ') # just assume ET??
#print " tz = ", tz, " datetime =", datetimestr
hand.startTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S") # also timezone at end, e.g. " ET"
hand.startTime = removeET(hand.startTime)
hand.startTime = HandHistoryConverter.changeTimezone(hand.startTime, "ET", "UTC")
if key == 'HID':
hand.handid = info[key]
if key == 'TOURNO':