small amend white-spaces (no functional changes) + a bit optimized `zone2offset`

pull/1792/head
sebres 8 years ago
parent 9f41d1e381
commit 39c4acf6bd

@ -107,17 +107,17 @@ def zone2offset(tz, dt):
been validated already)
dt: datetime instance for offset computation
"""
if isinstance(tz, basestring):
if len(tz) <= 3: # short tz (hh only)
# [+-]hh --> [+-]hh*60
return int(tz)*60
if tz[3] != ':':
# [+-]hhmm --> [+-]1 * (hh*60 + mm)
return int(tz[0]+'1') * (int(tz[1:3])*60 + int(tz[3:5]))
else:
# [+-]hh:mm --> [+-]1 * (hh*60 + mm)
return int(tz[0]+'1') * (int(tz[1:3])*60 + int(tz[4:6]))
return tz
if isinstance(tz, int):
return tz
if len(tz) <= 3: # short tz (hh only)
# [+-]hh --> [+-]hh*60
return int(tz)*60
if tz[3] != ':':
# [+-]hhmm --> [+-]1 * (hh*60 + mm)
return (-1 if tz[0] == '-' else 1) * (int(tz[1:3])*60 + int(tz[3:5]))
else:
# [+-]hh:mm --> [+-]1 * (hh*60 + mm)
return (-1 if tz[0] == '-' else 1) * (int(tz[1:3])*60 + int(tz[4:6]))
def reGroupDictStrptime(found_dict, msec=False, default_tz=None):
"""Return time from dictionary of strptime fields

@ -99,16 +99,16 @@ class DateDetectorTest(LogCaptureTestCase):
('UTC', logdt, dtUTC), # UTC
('UTC-0430', logdt, dt(2017, 1, 23, 19, 30)),
('GMT+12', logdt, dt(2017, 1, 23, 3, 0)),
(None, logdt, dt(2017, 1, 23, 14, 0)), # default CET in our test-framework
(None, logdt, dt(2017, 1, 23, 14, 0)), # default CET in our test-framework
('UTC+0300', logdt+' GMT', dtUTC), # GMT wins
('UTC', logdt+' GMT', dtUTC), # GMT wins
('UTC-0430', logdt+' GMT', dtUTC), # GMT wins
(None, logdt+' GMT', dtUTC), # GMT wins
(None, logdt+' GMT', dtUTC), # GMT wins
('UTC', logdt+' -1045', dt(2017, 1, 24, 1, 45)), # -1045 wins
(None, logdt+' -10:45', dt(2017, 1, 24, 1, 45)), # -1045 wins
(None, logdt+' -10:45', dt(2017, 1, 24, 1, 45)), # -1045 wins
('UTC', logdt+' +0945', dt(2017, 1, 23, 5, 15)), # +0945 wins
(None, logdt+' +09:45', dt(2017, 1, 23, 5, 15)), # +0945 wins
(None, logdt+' Z', dtUTC), # Z wins (UTC)
(None, logdt+' +09:45', dt(2017, 1, 23, 5, 15)), # +0945 wins
(None, logdt+' Z', dtUTC), # Z wins (UTC)
):
logSys.debug('== test %r with TZ %r', log, tz)
dd.default_tz=tz; datelog, _ = dd.getTime(log)

Loading…
Cancel
Save