/usr/lib/python2.7/dist-packages/MLBviewer/mlbGameTime.py is in mlbviewer 2015.sf.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #!/usr/bin/env python
import datetime
from datetime import tzinfo
import time
import re
# In the US, since 2007, DST starts at 2am (standard time) on the second
# Sunday in March, which is the first Sunday on or after Mar 8.
DSTSTART = datetime.datetime(1, 3, 8, 2)
# and ends at 2am (DST time; 1am standard time) on the first Sunday of Nov.
DSTEND = datetime.datetime(1, 11, 1, 1)
def first_sunday_on_or_after(dt):
days_to_go = 6 - dt.weekday()
if days_to_go:
dt += datetime.timedelta(days_to_go)
return dt
class MLBGameTime:
def __init__(self,listtime,shift=None):
self.eastern = listtime
self.shift = shift
# defensive code to ignore old format without the ":"
if self.shift and not re.search(":",self.shift):
self.shift=None
def dst(self):
dststart, dstend = DSTSTART, DSTEND
dston = first_sunday_on_or_after(dststart.replace(year=self.eastern.year))
dstoff = first_sunday_on_or_after(dstend.replace(year=self.eastern.year))
if dston <= self.eastern.replace(tzinfo=None) < dstoff:
return datetime.timedelta(hours=1)
else:
return datetime.timedelta(0)
def utcoffset(self):
return datetime.timedelta(hours=5) - self.dst()
def localize(self):
if self.shift is not None and self.shift != '':
return self.override(offset=self.shift)
utctime = self.eastern + self.utcoffset()
now = time.localtime()
localzone = (time.timezone,time.altzone)[now.tm_isdst]
localoffset = datetime.timedelta(0,localzone)
localtime = utctime - localoffset
return localtime
def customoffset(self,time_shift,reverse=False):
try:
plus_minus=re.search('[+-]',time_shift).group()
(hrs,min)=time_shift[1:].split(':')
offset=datetime.timedelta(hours=int(plus_minus+hrs),minutes=int(min))
offset=(offset,offset*-1)[reverse]
except:
offset=datetime.timedelta(0,0)
return offset
def override(self,offset,reverse=False):
if offset is not None and offset != '':
localoffset = self.customoffset(time_shift=offset,reverse=reverse)
localtime = self.eastern + localoffset
return localtime
else:
return self.eastern
|