Browse Source

Support "now" as a timestamp argument

tags/nilmdb-0.2^2
Jim Paris 9 years ago
parent
commit
58c7c8f6ff
2 changed files with 6 additions and 5 deletions
  1. +4
    -4
      nilmdb/cmdline/cmdline.py
  2. +2
    -1
      tests/test_cmdline.py

+ 4
- 4
nilmdb/cmdline/cmdline.py View File

@@ -48,10 +48,10 @@ class Cmdline(object):
If the string doesn't contain a timestamp, the current local
timezone is assumed (e.g. from the TZ env var).
"""
# If string doesn't contain at least 6 digits, consider it
# invalid. smartparse might otherwise accept empty strings
# and strings with just separators.
if len(re.findall(r"\d", toparse)) < 6:
# If string isn't "now" and doesn't contain at least 4 digits,
# consider it invalid. smartparse might otherwise accept
# empty strings and strings with just separators.
if toparse != "now" and len(re.findall(r"\d", toparse)) < 4:
raise ValueError("not enough digits for a timestamp")

# Try to just parse the time as given


+ 2
- 1
tests/test_cmdline.py View File

@@ -340,9 +340,10 @@ class TestCmdline(object):
eq_(cmd.parse_time("hi there 20120405 1400-0400 testing! 123"), test)
eq_(cmd.parse_time("20120405 1800 UTC"), test)
eq_(cmd.parse_time("20120405 1400-0400 UTC"), test)
for badtime in [ "20120405 1400-9999", "hello", "-", "", "14:00" ]:
for badtime in [ "20120405 1400-9999", "hello", "-", "", "4:00" ]:
with assert_raises(ValueError):
x = cmd.parse_time(badtime)
x = cmd.parse_time("now")
eq_(cmd.parse_time("snapshot-20120405-140000.raw.gz"), test)
eq_(cmd.parse_time("prep-20120405T1400"), test)



Loading…
Cancel
Save