Skip to content

Commit f60c31b

Browse files
author
Neil Grey
committed
For #35260: Refactoring scoping of sgtimezone so that dates are picklable and convertable
1 parent e49a9b3 commit f60c31b

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

shotgun_api3/lib/sgtimezone.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
# current users of api2 to install new modules and modify PYTHONPATH info.
66
# ----------------------------------------------------------------------------
77

8-
class SgTimezone(object):
9-
from datetime import tzinfo, timedelta, datetime
10-
import time as _time
8+
from datetime import tzinfo, timedelta, datetime
9+
import time as _time
1110

11+
class SgTimezone(object):
12+
1213
ZERO = timedelta(0)
1314
STDOFFSET = timedelta(seconds = -_time.timezone)
1415
if _time.daylight:
@@ -18,41 +19,40 @@ class SgTimezone(object):
1819
DSTDIFF = DSTOFFSET - STDOFFSET
1920

2021
def __init__(self):
21-
self.utc = self.UTC()
22-
self.local = self.LocalTimezone()
22+
self.utc = UTC()
23+
self.local = LocalTimezone()
2324

24-
class UTC(tzinfo):
25-
26-
def utcoffset(self, dt):
27-
return SgTimezone.ZERO
28-
29-
def tzname(self, dt):
30-
return "UTC"
31-
32-
def dst(self, dt):
33-
return SgTimezone.ZERO
25+
class UTC(tzinfo):
26+
27+
def utcoffset(self, dt):
28+
return SgTimezone.ZERO
3429

35-
class LocalTimezone(tzinfo):
36-
37-
def utcoffset(self, dt):
38-
if self._isdst(dt):
39-
return SgTimezone.DSTOFFSET
40-
else:
41-
return SgTimezone.STDOFFSET
42-
43-
def dst(self, dt):
44-
if self._isdst(dt):
45-
return SgTimezone.DSTDIFF
46-
else:
47-
return SgTimezone.ZERO
48-
49-
def tzname(self, dt):
50-
return _time.tzname[self._isdst(dt)]
51-
52-
def _isdst(self, dt):
53-
tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)
54-
import time as _time
55-
stamp = _time.mktime(tt)
56-
tt = _time.localtime(stamp)
57-
return tt.tm_isdst > 0
30+
def tzname(self, dt):
31+
return "UTC"
32+
33+
def dst(self, dt):
34+
return SgTimezone.ZERO
5835

36+
class LocalTimezone(tzinfo):
37+
38+
def utcoffset(self, dt):
39+
if self._isdst(dt):
40+
return SgTimezone.DSTOFFSET
41+
else:
42+
return SgTimezone.STDOFFSET
43+
44+
def dst(self, dt):
45+
if self._isdst(dt):
46+
return SgTimezone.DSTDIFF
47+
else:
48+
return SgTimezone.ZERO
49+
50+
def tzname(self, dt):
51+
return _time.tzname[self._isdst(dt)]
52+
53+
def _isdst(self, dt):
54+
tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)
55+
import time as _time
56+
stamp = _time.mktime(tt)
57+
tt = _time.localtime(stamp)
58+
return tt.tm_isdst > 0

0 commit comments

Comments
 (0)