[PATCH] add more support for dates with slashes
Haszlakiewicz, Eric
EHASZLA at transunion.com
Fri Oct 21 11:44:31 CDT 2011
Here's a patch that adds support for several additional date formats that use slashes instead of dashes (plus some more tests to make sure everything still works).
# HG changeset patch
# User Eric Haszlakiewicz <hawicz at gmail.com>
# Date 1319215280 14400
# Node ID 89a5617493747a9e58a47a244a5091e0c381c921
# Parent d4addef0ec74370fbf75b138d06f8ad93d3038ff
Support full date formats with slashes.
diff --git a/mercurial/help/dates.txt b/mercurial/help/dates.txt
--- a/mercurial/help/dates.txt
+++ b/mercurial/help/dates.txt
@@ -15,9 +15,10 @@
- ``2006-12-06 13:18:29`` (ISO 8601 format)
- ``2006-12-6 13:18``
- ``2006-12-6``
-- ``12-6``
+- ``12-6`` (Dec 6, year assumed)
- ``12/6``
-- ``12/6/6`` (Dec 6 2006)
+- ``2006/12/6``
+- ``2006/12/06 13:18:29``
Lastly, there is Mercurial's internal format:
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -147,6 +147,11 @@
'%m/%d',
'%m/%d/%y',
'%m/%d/%Y',
+ '%Y/%m/%d %H:%M:%S',
+ '%Y/%m/%d %I:%M:%S%p',
+ '%Y/%m/%d %H:%M',
+ '%Y/%m/%d %I:%M%p',
+ '%Y/%m/%d',
'%a %b %d %H:%M:%S %Y',
'%a %b %d %I:%M:%S%p %Y',
'%a, %d %b %Y %H:%M:%S', # GNU coreutils "/bin/date --rfc-2822"
diff --git a/tests/test-parse-date.t b/tests/test-parse-date.t
--- a/tests/test-parse-date.t
+++ b/tests/test-parse-date.t
@@ -93,6 +93,44 @@
standard: Wed Feb 01 13:00:30 2006 +0000
$ hg debugdate "1:00:30PM" > /dev/null
+Test the limits of 32-bit dates
+
+ $ hg debugdate "2038-01-19 03:14:07 +0000"
+ internal: 2147483647 0
+ standard: Tue Jan 19 03:14:07 2038 +0000
+ $ hg debugdate "2038-01-19 03:14:08 +0000"
+ abort: date exceeds 32 bits: 2147483648
+ [255]
+
+Test using dates with slashes
+
+ $ RES1=`hg debugdate "01/02 +0000"`
+ $ THISYEAR=`date +%Y`
+ $ RES2=`hg debugdate "01/02/${THISYEAR} +0000"`
+ $ ([ "$RES1" = "$RES2" ] && echo OK) || (echo "$RES1" ; false)
+ OK
+ $ hg debugdate "01/02/07 +0000"
+ internal: 1167696000 0
+ standard: Tue Jan 02 00:00:00 2007 +0000
+ $ hg debugdate "01/02/2007 +0000"
+ internal: 1167696000 0
+ standard: Tue Jan 02 00:00:00 2007 +0000
+ $ hg debugdate "2038/01/19 03:14:07 +0000"
+ internal: 2147483647 0
+ standard: Tue Jan 19 03:14:07 2038 +0000
+ $ hg debugdate "2006/02/01 1:00:30PM +0000"
+ internal: 1138798830 0
+ standard: Wed Feb 01 13:00:30 2006 +0000
+ $ hg debugdate "2038/01/18 22:14 +0000"
+ internal: 2147465640 0
+ standard: Mon Jan 18 22:14:00 2038 +0000
+ $ hg debugdate "2006/02/01 1:00PM +0000"
+ internal: 1138798800 0
+ standard: Wed Feb 01 13:00:00 2006 +0000
+ $ hg debugdate "2006/02/01 +0000"
+ internal: 1138752000 0
+ standard: Wed Feb 01 00:00:00 2006 +0000
+
Test date formats with '>' or '<' accompanied by space characters
$ hg log -d '>' --template '{date|date}\n'
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 474 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20111021/be3381a5/attachment.pgp>
More information about the Mercurial-devel
mailing list