remove @ prefix for timespecs

This commit is contained in:
Josh Holtrop 2010-12-29 00:22:30 -05:00
parent 9ea2fbed41
commit fac74e651a
2 changed files with 12 additions and 8 deletions

View File

@ -25,8 +25,7 @@ class Command:
parts = cmdline.split(None, 1) parts = cmdline.split(None, 1)
if len(parts) > 1: if len(parts) > 1:
timespec = parts[0].strip() timespec = parts[0].strip()
if timespec[0] == '@': if self.parseTimeSpec(timespec):
self.time = self.parseTimeSpec(timespec[1:])
parts = parts[1].split(None, 1) parts = parts[1].split(None, 1)
if len(parts) == 1: if len(parts) == 1:
command = parts[0].strip() command = parts[0].strip()
@ -41,6 +40,7 @@ class Command:
def parseTimeSpec(self, timespec): def parseTimeSpec(self, timespec):
the_time = self.time the_time = self.time
matched = False
m = re.match('^(?:(\d{4})[-/])?(\d{1,2})[-/](\d{1,2}),(.+)$', timespec) m = re.match('^(?:(\d{4})[-/])?(\d{1,2})[-/](\d{1,2}),(.+)$', timespec)
if m is not None: if m is not None:
# a date was given # a date was given
@ -62,6 +62,7 @@ class Command:
elif len(am_pm) >= 1 and am_pm[0] == 'a' and h == 12: elif len(am_pm) >= 1 and am_pm[0] == 'a' and h == 12:
h = 0 h = 0
the_time = the_time.replace(hour = h, minute = mins, second = 0) the_time = the_time.replace(hour = h, minute = mins, second = 0)
matched = True
else: else:
m = re.match('^([-+])(\d+(?:\.\d+)?)([hms])?$', timespec, re.I) m = re.match('^([-+])(\d+(?:\.\d+)?)([hms])?$', timespec, re.I)
if m is not None: if m is not None:
@ -80,4 +81,7 @@ class Command:
the_time -= delta the_time -= delta
else: else:
the_time += delta the_time += delta
return the_time matched = True
if matched:
self.time = the_time
return matched

10
test
View File

@ -28,16 +28,16 @@ def main():
testcmd('out', 'out', '') testcmd('out', 'out', '')
testcmd('fill', 'fill', '') testcmd('fill', 'fill', '')
testcmd('adjust', 'adjust', '') testcmd('adjust', 'adjust', '')
testcmd('report', 'report', '') testcmd('2 report', 'report', '')
testcmd('show', 'show', '') testcmd('show', 'show', '')
testcmd('@5pm out', 'out', '') testcmd('5pm out', 'out', '')
testcmd('show 45h', 'show', '45h') testcmd('show 45h', 'show', '45h')
testcmd('fill 40h', 'fill', '40h') testcmd('fill 40h', 'fill', '40h')
testcmd('arlx', 'start', 'arlx') testcmd('-10m arlx', 'start', 'arlx')
testcmd(' adjust -10m ', 'adjust', '-10m') testcmd(' adjust -10m ', 'adjust', '-10m')
testcmd(' @9:45 wr: nog: pbit ram test ', testcmd(' 9:45 wr: nog: pbit ram test ',
'start', 'wr: nog: pbit ram test') 'start', 'wr: nog: pbit ram test')
testcmd('@12/14,3pm start arlx', 'start', 'arlx') testcmd('12/14,3pm start arlx', 'start', 'arlx')
if n_tests == n_pass: if n_tests == n_pass:
print " >= SUCCESS <=" print " >= SUCCESS <="
else: else: