Commit 6307c52c authored by bescoto's avatar bescoto

Times like "Mon Jun 5 11:00:23 1997" now recognized


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@757 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent b37601c3
......@@ -13,6 +13,9 @@ Fix a traceback due to an off-by-1 error in "--remove-older-than nB".
Fix a security violation when restoring from a remote repository.
(Patch from Charles Duffy.)
Added times like "Mon Jun 5 11:00:23 1997" to the recognized time
strings. (Suggested by Wolfgang Dautermann.)
New in v1.1.5 (2006/01/01)
--------------------------
......
......@@ -96,6 +96,11 @@ def stringtopretty(timestring):
"""Return pretty version of time given w3 time string"""
return timetopretty(stringtotime(timestring))
def prettytotime(prettystring):
"""Converts time like "Mon Jun 5 11:00:23" to epoch sec, or None"""
try: return time.mktime(time.strptime(prettystring))
except ValueError: return None
def inttopretty(seconds):
"""Convert num of seconds to readable string like "2 hours"."""
partlist = []
......@@ -222,6 +227,10 @@ the day).""" % timestr)
if _session_regexp.search(timestr):
return time_from_session(int(timestr[:-1]), rp)
# Try for long time, like "Mon Jun 5 11:00:23 1990"
t = prettytotime(timestr)
if t is not None: return t
try: # test for an interval, like "2 days ago"
return curtime - intstringtoseconds(timestr)
except TimeException: pass
......
......@@ -24,6 +24,7 @@ compare. This uses elements of the backup and restore modules.
"""
from __future__ import generators
import Globals, restore, rorpiter, log, backup, static, rpath, hash, robust
def Compare(src_rp, mirror_rp, inc_rp, compare_time):
......
......@@ -72,6 +72,14 @@ class TimeTest(unittest.TestCase):
assert Time.inttopretty(3661) == "1 hour 1 minute 1 second"
assert Time.inttopretty(353.234234) == "5 minutes 53.23 seconds"
def testPrettyTimes(self):
"""Convert seconds to pretty and back"""
now = int(time.time())
for i in [1, 200000, now]:
assert Time.prettytotime(Time.timetopretty(i)) == i, i
assert Time.prettytotime("now") is None
assert Time.prettytotime("12314") is None
def testGenericString(self):
"""Test genstrtotime, conversion of arbitrary string to time"""
g2t = Time.genstrtotime
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment