summaryrefslogtreecommitdiff
path: root/rdiff-backup/rdiff_backup/Time.py
diff options
context:
space:
mode:
authorbescoto <bescoto@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2005-04-06 05:51:59 +0000
committerbescoto <bescoto@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2005-04-06 05:51:59 +0000
commit5a8298c0c2c2569c3f3c508d1a0df4bca71ddf8a (patch)
tree5323c1e8f0a1509900eedf5e8561f6a4d6381a92 /rdiff-backup/rdiff_backup/Time.py
parentcf7284af553cb1e4eb622369f82453165a392a7a (diff)
downloadrdiff-backup-5a8298c0c2c2569c3f3c508d1a0df4bca71ddf8a.tar.gz
Another timezone fix, in response to bug Randall Nortman reported
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@576 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
Diffstat (limited to 'rdiff-backup/rdiff_backup/Time.py')
-rw-r--r--rdiff-backup/rdiff_backup/Time.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/rdiff-backup/rdiff_backup/Time.py b/rdiff-backup/rdiff_backup/Time.py
index 553dcf7..b096510 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, sys
+import time, types, re, sys, calendar
import Globals
@@ -35,7 +35,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"""
@@ -64,7 +63,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
@@ -83,9 +82,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
@@ -137,13 +135,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 = "+"