def kw_begin(self, val):
i = iter(val.split())
d = dict(zip(i, i))
tm = time.localtime()
if not 'time' in d:
sys.exit('Must specify start time')
t_sec = time.strptime(d['time'], '%H:%M')
if 'date' in d:
t_day = time.strptime(d['date'], '%Y-%m-%d')
else:
t_day = tm
off = 0
dst = tm.tm_isdst
if 'zone' in d:
if d['zone'] == 'zulu':
off = int(time.time() - time.mktime(time.gmtime())) / 60
off = off * 60
dst = 0
elif d['zone'] != 'local':
m = re.match('([+-]?)(\d{2}):?(\d{2})?', d['zone'])
if not m:
sys.exit('Invalid timezone syntax')
off = int(m.group(2)) * 3600 + int(m.group(3) or 0) * 60
off = off * -1 if m.group(1) == '-' else off
t = time.struct_time((t_day.tm_year, t_day.tm_mon, t_day.tm_mday,
t_sec.tm_hour, t_sec.tm_min, t_sec.tm_sec,
0, 0, dst))
self.start_ms = (int(time.mktime(t)) + off) * 1000
self.date = time.strftime('%Y-%m-%d',
time.localtime(self.start_ms / 1000))
评论列表
文章目录