Skip to content

Commit

Permalink
drop support for plain Unix date output parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sbailey committed Sep 25, 2020
1 parent 02f678f commit b3659a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
10 changes: 5 additions & 5 deletions py/desiutil/test/test_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ def test_parsetime(self):
@unittest.skipUnless(dateutil_installed, "dateutil not installed")
def test_parsetime_dateutil(self):
"""If dateutil installed, test fancy date string parsing"""
t0 = parsetime("Tue Sep 22 13:42:26 PDT 2020")
# t0 = parsetime("Tue Sep 22 13:42:26 PDT 2020")
# self.assertAlmostEqual(t0, 1600807346.0)
t1 = parsetime("2020-09-22T13:42:26-07:00")
self.assertAlmostEqual(t0, t1)
self.assertAlmostEqual(t0, 1600807346.0)
self.assertAlmostEqual(t1, 1600807346.0)

with self.assertRaises(ValueError):
t2 = parsetime("My Birthday")

@unittest.skipIf(dateutil_installed, "dateutil installed")
def test_parsetime_no_dateutil(self):
"""If dateutil not installed, confirm failure modes"""
with unittest.assertRaises(ValueError):
t0 = parsetime("Tue Sep 22 13:42:26 PDT 2020")
# with unittest.assertRaises(ValueError):
# t0 = parsetime("Tue Sep 22 13:42:26 PDT 2020")
with unittest.assertRaises(ValueError):
t1 = parsetime("2020-09-22T13:42:26-07:00")

Expand Down
11 changes: 3 additions & 8 deletions py/desiutil/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,9 @@ def parsetime(t):
try:
t = dateutil.parser.parse(t).timestamp()
except:
try:
#- Travis CI doesn't know about US timezones...
tzinfos = {"PST": -8*3600, "PDT": -7*3600, "MST":-7*3600, "MDT":-6*3600}
t = dateutil.parser.parse(t, tzinfos=tzinfos).timestamp()
except:
raise ValueError(f"Can't parse start time {t}; " \
"use int/float or ISO-8601 or " \
"Unix `date` output")
raise ValueError(f"Can't parse start time {t}; " \
"use int/float or ISO-8601 or " \
"Unix `date +%s` output")

return t

Expand Down

0 comments on commit b3659a8

Please sign in to comment.