[PATCH 2 of 3 STABLE] date: parse ISO-style Z and +hh:mm timezone specs

Matt Mackall mpm at selenic.com
Wed Jul 27 16:48:41 EDT 2016


# HG changeset patch
# User Matt Mackall <mpm at selenic.com>
# Date 1469650834 18000
#      Wed Jul 27 15:20:34 2016 -0500
# Branch stable
# Node ID a8d5ca11a21b8c833577e9265b3a16f78a528c63
# Parent  d88bdf016df204daf510921b38d5250336cc9991
date: parse ISO-style Z and +hh:mm timezone specs

diff -r d88bdf016df2 -r a8d5ca11a21b mercurial/util.py
--- a/mercurial/util.py	Wed Jul 27 15:14:19 2016 -0500
+++ b/mercurial/util.py	Wed Jul 27 15:20:34 2016 -0500
@@ -1760,6 +1760,18 @@
         minutes = int(s[-2:])
         return -sign * (hours * 60 + minutes) * 60, s[:-5].rstrip()
 
+    # ISO8601 trailing Z
+    if s.endswith("Z") and s[-2:-1].isdigit():
+        return 0, s[:-1]
+
+    # ISO8601-style [+-]hh:mm
+    if (len(s) >= 6 and s[-6] in "+-" and s[-3] == ":" and
+        s[-5:-3].isdigit() and s[-2:].isdigit()):
+        sign = (s[-6] == "+") and 1 or -1
+        hours = int(s[-5:-3])
+        minutes = int(s[-2:])
+        return -sign * (hours * 60 + minutes) * 60, s[:-6]
+
     return None, s
 
 def strdate(string, format, defaults=[]):


More information about the Mercurial-devel mailing list