diff babel/messages/catalog.py @ 429:08e2d18163d9

Fix Catalog._set_mime_headers' handing of negative offsets. Submitted by: Asheesh Laroia (Creative Commons) Closes: #165
author jruigrok
date Mon, 16 Mar 2009 17:49:48 +0000
parents 52492583006a
children 86c4fe7de244
line wrap: on
line diff
--- a/babel/messages/catalog.py
+++ b/babel/messages/catalog.py
@@ -349,11 +349,29 @@
             elif name == 'pot-creation-date':
                 # FIXME: this should use dates.parse_datetime as soon as that
                 #        is ready
-                value, tzoffset, _ = re.split('[+-](\d{4})$', value, 1)
+                value, tzoffset, _ = re.split('([+-]\d{4})$', value, 1)
+
                 tt = time.strptime(value, '%Y-%m-%d %H:%M')
                 ts = time.mktime(tt)
-                tzoffset = FixedOffsetTimezone(int(tzoffset[:2]) * 60 +
-                                               int(tzoffset[2:]))
+
+                # Seprate the offset into a sign component, hours, and minutes
+                plus_minus_s, rest = tzoffset[0], tzoffset[1:]
+                hours_offset_s, mins_offset_s = rest[:2], rest[2:]
+
+                # Make them all integers
+                plus_minus = int(plus_minus_s + '1')
+                hours_offset = int(hours_offset_s)
+                mins_offset = int(mins_offset_s)
+
+                # Calculate net offset
+                net_mins_offset = hours_offset * 60
+                net_mins_offset += mins_offset
+                net_mins_offset *= plus_minus
+
+                # Create an offset object
+                tzoffset = FixedOffsetTimezone(net_mins_offset)
+
+                # Store the offset in a datetime object
                 dt = datetime.fromtimestamp(ts)
                 self.creation_date = dt.replace(tzinfo=tzoffset)
             elif name == 'po-revision-date':
@@ -361,11 +379,29 @@
                 if 'YEAR' not in value:
                     # FIXME: this should use dates.parse_datetime as soon as
                     #        that is ready
-                    value, tzoffset, _ = re.split('[+-](\d{4})$', value, 1)
+                    value, tzoffset, _ = re.split('([+-]\d{4})$', value, 1)
                     tt = time.strptime(value, '%Y-%m-%d %H:%M')
                     ts = time.mktime(tt)
-                    tzoffset = FixedOffsetTimezone(int(tzoffset[:2]) * 60 +
-                                                   int(tzoffset[2:]))
+
+                    # Seprate the offset into a sign component, hours, and
+                    # minutes
+                    plus_minus_s, rest = tzoffset[0], tzoffset[1:]
+                    hours_offset_s, mins_offset_s = rest[:2], rest[2:]
+
+                    # Make them all integers
+                    plus_minus = int(plus_minus_s + '1')
+                    hours_offset = int(hours_offset_s)
+                    mins_offset = int(mins_offset_s)
+
+                    # Calculate net offset
+                    net_mins_offset = hours_offset * 60
+                    net_mins_offset += mins_offset
+                    net_mins_offset *= plus_minus
+
+                    # Create an offset object
+                    tzoffset = FixedOffsetTimezone(net_mins_offset)
+
+                    # Store the offset in a datetime object
                     dt = datetime.fromtimestamp(ts)
                     self.revision_date = dt.replace(tzinfo=tzoffset)
 
Copyright (C) 2012-2017 Edgewall Software