diff options
author | owsla <owsla@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109> | 2009-01-03 23:18:35 +0000 |
---|---|---|
committer | owsla <owsla@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109> | 2009-01-03 23:18:35 +0000 |
commit | 247258bb5cd325c311188dd65b3f351e64bc5454 (patch) | |
tree | 4dfb10c0835303245482954eaa9abefe7b54b495 /rdiff-backup/rdiff_backup/Time.py | |
parent | a0d43616f7f51127bed7a8dd3866fa6d22b8c8b5 (diff) | |
download | rdiff-backup-247258bb5cd325c311188dd65b3f351e64bc5454.tar.gz |
New option: --use-compatible-timestamps, which causes rdiff-backup to use - asthe hour/minute/second separator instead of :. Enabled by default on systems
which require : to be escaped. (Oliver Mulatz)
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@996 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
Diffstat (limited to 'rdiff-backup/rdiff_backup/Time.py')
-rw-r--r-- | rdiff-backup/rdiff_backup/Time.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/rdiff-backup/rdiff_backup/Time.py b/rdiff-backup/rdiff_backup/Time.py index fee2276..02e3eeb 100644 --- a/rdiff-backup/rdiff_backup/Time.py +++ b/rdiff-backup/rdiff_backup/Time.py @@ -61,8 +61,13 @@ def setprevtime_local(timeinseconds, timestr): prevtime, prevtimestr = timeinseconds, timestr def timetostring(timeinseconds): - """Return w3 datetime compliant listing of timeinseconds""" - s = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(timeinseconds)) + """Return w3 datetime compliant listing of timeinseconds, or one in + which :'s have been replaced with -'s""" + if not Globals.use_compatible_timestamps: + format_string = "%Y-%m-%dT%H:%M:%S" + else: + format_string = "%Y-%m-%dT%H-%M-%S" + s = time.strftime(format_string, time.localtime(timeinseconds)) return s + gettzd(timeinseconds) def stringtotime(timestring): @@ -72,10 +77,13 @@ def stringtotime(timestring): like a w3 datetime string, return None. """ + + regexp = re.compile('[-:]') + try: date, daytime = timestring[:19].split("T") year, month, day = map(int, date.split("-")) - hour, minute, second = map(int, daytime.split(":")) + hour, minute, second = map(int, regexp.split(daytime)) assert 1900 < year < 2100, year assert 1 <= month <= 12 assert 1 <= day <= 31 @@ -157,16 +165,18 @@ def gettzd(timeinseconds = None): elif offset < 0: prefix = "-" else: return "Z" # time is already in UTC + if Globals.use_compatible_timestamps: time_separator = '-' + else: time_separator = ':' hours, minutes = map(abs, divmod(offset, 60)) assert 0 <= hours <= 23 assert 0 <= minutes <= 59 - return "%s%02d:%02d" % (prefix, hours, minutes) + return "%s%02d%s%02d" % (prefix, hours, time_separator, minutes) def tzdtoseconds(tzd): """Given w3 compliant TZD, return how far ahead UTC is""" if tzd == "Z": return 0 assert len(tzd) == 6 # only accept forms like +08:00 for now - assert (tzd[0] == "-" or tzd[0] == "+") and tzd[3] == ":" + assert (tzd[0] == "-" or tzd[0] == "+") and (tzd[3] == ":" or tzd[3] == "-") return -60 * (60 * int(tzd[:3]) + int(tzd[4:])) def cmp(time1, time2): |