[PATCH 3 of 3] date: accept broader range of ISO 8601 time specs

Matt Mackall mpm at selenic.com
Thu Jul 28 15:56:28 EDT 2016


# HG changeset patch
# User Matt Mackall <mpm at selenic.com>
# Date 1469650956 18000
#      Wed Jul 27 15:22:36 2016 -0500
# Branch stable
# Node ID 17fe38cc6a282a94ed5453b1163bc2f1548bfee9
# Parent  55dd37d5f475c04fe0373399740805f38240f9da
date: accept broader range of ISO 8601 time specs

The "normal" ISO date/time includes a T between date and time. It also
allows dropping the colons and seconds from the timespec. Add new
patterns for these forms as well as tests.

diff -r 55dd37d5f475 -r 17fe38cc6a28 mercurial/util.py
--- a/mercurial/util.py	Wed Jul 27 15:20:34 2016 -0500
+++ b/mercurial/util.py	Wed Jul 27 15:22:36 2016 -0500
@@ -440,7 +440,14 @@
 
 # used by parsedate
 defaultdateformats = (
-    '%Y-%m-%d %H:%M:%S',
+    '%Y-%m-%dT%H:%M:%S', # the 'real' ISO8601
+    '%Y-%m-%dT%H:%M',    #   without seconds
+    '%Y-%m-%dT%H%M%S',   # another awful but legal variant without :
+    '%Y-%m-%dT%H%M',     #   without seconds
+    '%Y-%m-%d %H:%M:%S', # our common legal variant
+    '%Y-%m-%d %H:%M',    #   without seconds
+    '%Y-%m-%d %H%M%S',   # without :
+    '%Y-%m-%d %H%M',     #   without seconds
     '%Y-%m-%d %I:%M:%S%p',
     '%Y-%m-%d %H:%M',
     '%Y-%m-%d %I:%M%p',
diff -r 55dd37d5f475 -r 17fe38cc6a28 tests/test-parse-date.t
--- a/tests/test-parse-date.t	Wed Jul 27 15:20:34 2016 -0500
+++ b/tests/test-parse-date.t	Wed Jul 27 15:22:36 2016 -0500
@@ -258,3 +258,31 @@
   $ hg log -d today --template '{desc}\n'
   Explicitly committed now.
   today is a good day to code
+
+Test parsing various ISO8601 forms
+
+  $ hg debugdate "2016-07-27T12:10:21"
+  internal: 1469646621 * (glob)
+  standard: Wed Jul 27 12:10:21 2016 -0700
+  $ hg debugdate "2016-07-27T12:10:21Z"
+  internal: 1469621421 0
+  standard: Wed Jul 27 12:10:21 2016 +0000
+  $ hg debugdate "2016-07-27T12:10:21+00:00"
+  internal: 1469621421 0
+  standard: Wed Jul 27 12:10:21 2016 +0000
+  $ hg debugdate "2016-07-27T121021Z"
+  internal: 1469621421 0
+  standard: Wed Jul 27 12:10:21 2016 +0000
+
+  $ hg debugdate "2016-07-27 12:10:21"
+  internal: 1469646621 * (glob)
+  standard: Wed Jul 27 12:10:21 2016 -0700
+  $ hg debugdate "2016-07-27 12:10:21Z"
+  internal: 1469621421 0
+  standard: Wed Jul 27 12:10:21 2016 +0000
+  $ hg debugdate "2016-07-27 12:10:21+00:00"
+  internal: 1469621421 0
+  standard: Wed Jul 27 12:10:21 2016 +0000
+  $ hg debugdate "2016-07-27 121021Z"
+  internal: 1469621421 0
+  standard: Wed Jul 27 12:10:21 2016 +0000


More information about the Mercurial-devel mailing list