changeset 128:6b5925d56ecd

dulwich: fix handling of negative time offsets.
author Dmitriy Taychenachev <dimichxp@gmail.com>
date Thu, 14 May 2009 20:18:58 -0700
parents b3be536e3f50
children ed4e8c2cd016
files dulwich/objects.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/dulwich/objects.py	Mon May 11 16:03:57 2009 -0700
+++ b/dulwich/objects.py	Thu May 14 20:18:58 2009 -0700
@@ -479,15 +479,19 @@
 
 def parse_timezone(text):
     offset = int(text)
+    signum = (offset < 0) and -1 or 1
+    offset = abs(offset)
     hours = int(offset / 100)
     minutes = (offset % 100)
-    return (hours * 3600) + (minutes * 60)
+    return signum * (hours * 3600 + minutes * 60)
 
 
 def format_timezone(offset):
     if offset % 60 != 0:
         raise ValueError("Unable to handle non-minute offset.")
-    return '%+03d%02d' % (offset / 3600, (offset / 60) % 60)
+    sign = (offset < 0) and '-' or '+'
+    offset = abs(offset)
+    return '%c%02d%02d' % (sign, offset / 3600, (offset / 60) % 60)
 
 
 class Commit(ShaFile):