summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbescoto <bescoto@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2005-04-07 18:09:41 +0000
committerbescoto <bescoto@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2005-04-07 18:09:41 +0000
commite16ab5aeb778d99a8982cb1a9ee4ff029121d93f (patch)
treec31930aa6186bd33c7f15fd9b3ed03d40bed0e9d
parent523892759f81af0429c1b48e6a8ceab981fbd33f (diff)
downloadrdiff-backup-e16ab5aeb778d99a8982cb1a9ee4ff029121d93f.tar.gz
Another timezone fix, in response to bug Randall Nortman reported
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/branches/r0-12@577 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
-rw-r--r--rdiff-backup/CHANGELOG3
-rw-r--r--rdiff-backup/rdiff_backup/Time.py20
-rw-r--r--rdiff-backup/testing/timetest.py12
3 files changed, 26 insertions, 9 deletions
diff --git a/rdiff-backup/CHANGELOG b/rdiff-backup/CHANGELOG
index 3edaddc..a31ecc5 100644
--- a/rdiff-backup/CHANGELOG
+++ b/rdiff-backup/CHANGELOG
@@ -8,6 +8,9 @@ Added Maximilian Mehnert's fix for too many open files bug.
Added fix for listing/restoring certain bad archives made when there
was a timezone bug. (Thanks to Stephen Isard)
+Fixed timezone bug. Hopefully this is the last one. (Thanks to
+Randall Nortman for bug report.)
+
New in v0.12.7 (2004/05/31)
---------------------------
diff --git a/rdiff-backup/rdiff_backup/Time.py b/rdiff-backup/rdiff_backup/Time.py
index 3fa872b..522c4c0 100644
--- a/rdiff-backup/rdiff_backup/Time.py
+++ b/rdiff-backup/rdiff_backup/Time.py
@@ -19,7 +19,7 @@
"""Provide time related exceptions and functions"""
-import time, types, re
+import time, types, re, calendar
import Globals
@@ -34,7 +34,6 @@ _genstr_date_regexp1 = re.compile("^(?P<year>[0-9]{4})[-/]"
_genstr_date_regexp2 = re.compile("^(?P<month>[0-9]{1,2})[-/]"
"(?P<day>[0-9]{1,2})[-/](?P<year>[0-9]{4})$")
curtime = curtimestr = None
-dst_in_effect = time.daylight and time.localtime()[8]
def setcurtime(curtime = None):
"""Sets the current time in curtime and curtimestr on all systems"""
@@ -63,7 +62,7 @@ def setprevtime_local(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 s + gettzd()
+ return s + gettzd(timeinseconds)
def stringtotime(timestring):
"""Return time in seconds from w3 timestring
@@ -82,9 +81,8 @@ def stringtotime(timestring):
assert 0 <= hour <= 23
assert 0 <= minute <= 59
assert 0 <= second <= 61 # leap seconds
- timetuple = (year, month, day, hour, minute, second, -1, -1, -1)
- if dst_in_effect: utc_in_secs = time.mktime(timetuple) - time.altzone
- else: utc_in_secs = time.mktime(timetuple) - time.timezone
+ timetuple = (year, month, day, hour, minute, second, -1, -1, 0)
+ utc_in_secs = calendar.timegm(timetuple)
return long(utc_in_secs) + tzdtoseconds(timestring[19:])
except (TypeError, ValueError, AssertionError): return None
@@ -136,13 +134,17 @@ page for more information.
interval_string = interval_string[match.end(0):]
return total
-def gettzd():
+def gettzd(timeinseconds = None):
"""Return w3's timezone identification string.
- Expresed as [+/-]hh:mm. For instance, PST is -08:00. Zone is
- coincides with what localtime(), etc., use.
+ Expresed as [+/-]hh:mm. For instance, PDT is -07:00 during
+ dayling savings and -08:00 otherwise. Zone is coincides with what
+ localtime(), etc., use. If no argument given, use the current
+ time.
"""
+ if timeinseconds is None: timeinseconds = time.time()
+ dst_in_effect = time.daylight and time.localtime(timeinseconds)[8]
if dst_in_effect: offset = -time.altzone/60
else: offset = -time.timezone/60
if offset > 0: prefix = "+"
diff --git a/rdiff-backup/testing/timetest.py b/rdiff-backup/testing/timetest.py
index 0ab8514..56052ca 100644
--- a/rdiff-backup/testing/timetest.py
+++ b/rdiff-backup/testing/timetest.py
@@ -94,5 +94,17 @@ class TimeTest(unittest.TestCase):
self.assertRaises(Time.TimeException, g2t, "")
self.assertRaises(Time.TimeException, g2t, "3q")
+ def testTimeZone(self):
+ """Test stringtotime on two strings straddling timezones"""
+ f = Time.stringtotime
+ invf = Time.timetostring
+ s1 = "2005-04-03T03:45:03-03:00"
+ s2 = "2005-04-03T02:45:03-03:00"
+ diff = f(s1) - f(s2)
+ assert diff == 3600, diff
+
+ assert f(invf(f(s1))) == f(s1), (s1, invf(f(s1)), f(invf(f(s1))), f(s1))
+ assert f(invf(f(s2))) == f(s2), (s2, f(invf(f(s2))), f(s2))
+
if __name__ == '__main__': unittest.main()