Patchwork parsedate: understand "now" as a shortcut for the current time

login
register
mail settings
Submitter Augie Fackler
Date Feb. 9, 2013, 9:57 p.m.
Message ID <a2906f188cb708ee3983.1360447046@augie-macbookair>
Download mbox | patch
Permalink /patch/912/
State Accepted
Commit b2586e2cc67ad7d446cdf8a78baccd34d5fa195f
Headers show

Comments

Augie Fackler - Feb. 9, 2013, 9:57 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1360445962 21600
# Node ID a2906f188cb708ee3983ac75551256c730b0cef9
# Parent  0b6e6eacc939c303136cb38af108e307d640c26e
parsedate: understand "now" as a shortcut for the current time
Bryan O'Sullivan - Feb. 9, 2013, 9:58 p.m.
On Sat, Feb 9, 2013 at 1:57 PM, Augie Fackler <raf@durin42.com> wrote:

> parsedate: understand "now" as a shortcut for the current time
>

LGTM.

Patch

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