changeset 3809:4d93b37b5963

parsedate: add UTC and GMT timezones
author Matt Mackall <mpm@selenic.com>
date Wed, 06 Dec 2006 13:13:42 -0600
parents d6529582942a
children 1d571ed26eed
files mercurial/util.py
diffstat 1 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Wed Dec 06 13:13:31 2006 -0600
+++ b/mercurial/util.py	Wed Dec 06 13:13:42 2006 -0600
@@ -1061,18 +1061,20 @@
 def strdate(string, format='%a %b %d %H:%M:%S %Y'):
     """parse a localized time string and return a (unixtime, offset) tuple.
     if the string cannot be parsed, ValueError is raised."""
-    def hastimezone(string):
-        return (string[-4:].isdigit() and
-               (string[-5] == '+' or string[-5] == '-') and
-               string[-6].isspace())
+    def timezone(string):
+        tz = string.split()[-1]
+        if tz[0] in "+-" and len(tz) == 5 and tz[1:].isdigit():
+            tz = int(tz)
+            offset = - 3600 * (tz / 100) - 60 * (tz % 100)
+            return offset
+        if tz == "GMT" or tz == "UTC":
+            return 0
+        return None
 
     # NOTE: unixtime = localunixtime + offset
-    if hastimezone(string):
-        date, tz = string[:-6], string[-5:]
-        tz = int(tz)
-        offset = - 3600 * (tz / 100) - 60 * (tz % 100)
-    else:
-        date, offset = string, None
+    offset, date = timezone(string), string
+    if offset != None:
+        date = " ".join(string.split()[:-1])
 
     # add missing elements
     if '%y' not in format.lower():