[PATCH] parsedate: understand "now" as a shortcut for the current time

Augie Fackler raf at durin42.com
Sat Feb 9 15:57:26 CST 2013


# HG changeset patch
# User Augie Fackler <raf at durin42.com>
# Date 1360445962 21600
# Node ID a2906f188cb708ee3983ac75551256c730b0cef9
# Parent  0b6e6eacc939c303136cb38af108e307d640c26e
parsedate: understand "now" as a shortcut for the current time

diff --git a/mercurial/help/dates.txt b/mercurial/help/dates.txt
--- a/mercurial/help/dates.txt
+++ b/mercurial/help/dates.txt
@@ -20,6 +20,7 @@
 - ``12/6/6`` (Dec 6 2006)
 - ``today`` (midnight)
 - ``yesterday`` (midnight)
+- ``now`` - right now
 
 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
@@ -1060,6 +1060,12 @@
                                                datetime.timedelta(days=1)\
                                               ).strftime('%b %d'))
     True
+    >>> now, tz = makedate()
+    >>> strnow, strtz = parsedate('now')
+    >>> (strnow - now) < 1
+    True
+    >>> tz == strtz
+    True
     """
     if not date:
         return 0, 0
@@ -1069,6 +1075,8 @@
         formats = defaultdateformats
     date = date.strip()
 
+    if date == _('now'):
+        return makedate()
     if date == _('today'):
         date = datetime.date.today().strftime('%b %d')
     elif date == _('yesterday'):
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
@@ -251,3 +251,8 @@
   $ hg ci -d "`sed -n '2p' dates`" -m "the time traveler's code"
   $ hg log -d yesterday --template '{desc}\n'
   the time traveler's code
+  $ echo "foo" >> a
+  $ hg commit -d now -m 'Explicitly committed now.'
+  $ hg log -d today --template '{desc}\n'
+  Explicitly committed now.
+  today is a good day to code


More information about the Mercurial-devel mailing list