Patchwork util: parsedate: Update to understand 'today' and 'yesterday' (issue 3764)

login
register
mail settings
Submitter Paul Cavallaro
Date Jan. 23, 2013, 12:28 a.m.
Message ID <1ad84126894a6d1127a7.1358900884@devrs153.prn1.facebook.com>
Download mbox | patch
Permalink /patch/717/
State Deferred
Headers show

Comments

Paul Cavallaro - Jan. 23, 2013, 12:28 a.m.
# HG changeset patch
# User Paul Cavallaro <ptc@fb.com>
# Date 1358900012 28800
# Node ID 1ad84126894a6d1127a7098b605df797f9e49c12
# Parent  1f794204abbd7dd4bc329ae0c7c4fd7ce56b33af
util: parsedate: Update to understand 'today' and 'yesterday' (issue 3764)
***
Adding support for "today" and "yesterday" to parsedate

Test Plan: Use `./hg log -d today` or another command
Wagner Bruna - Jan. 23, 2013, 2:48 p.m.
Em 22-01-2013 22:28, Paul Cavallaro escreveu:
> # HG changeset patch
> # User Paul Cavallaro <ptc@fb.com>
> # Date 1358900012 28800
> # Node ID 1ad84126894a6d1127a7098b605df797f9e49c12
> # Parent  1f794204abbd7dd4bc329ae0c7c4fd7ce56b33af
> util: parsedate: Update to understand 'today' and 'yesterday' (issue 3764)
> ***
> Adding support for "today" and "yesterday" to parsedate
> 
> Test Plan: Use `./hg log -d today` or another command

Thanks for the patch! Mercurial is currently on code freeze, so any new
feature will be on hold until after the next release (due to February 1st).
Could you please resend after that?

Also, I notice a couple issues with the commit message: "Update" shouldn't be
capitalized, and the space after "issue" will confuse our bugtracker parser.
Please also take a look at

http://mercurial.selenic.com/wiki/ContributingChanges

> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -1035,6 +1035,13 @@
>      if not formats:
>          formats = defaultdateformats
>      date = date.strip()
> +
> +    if date == 'today':
> +        date = datetime.date.today().strftime('%b %d')
> +    elif date == 'yesterday':

Could you also look for translated values (_('today') and _('yesterday')) here?

> +        date = (datetime.date.today() -
> +                datetime.timedelta(days=1)).strftime('%b %d')
> +
>      try:
>          when, offset = map(int, date.split(' '))
>      except ValueError:
> 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
> @@ -234,3 +234,13 @@
>    Sat Apr 15 13:30:00 2006 +0000
>    Wed Feb 01 13:00:30 2006 -0500
>    Wed Feb 01 13:00:30 2006 +0000
> +
> +Test issue 3764 (interpreting 'today' and 'yesterday')
> +  $ echo "hello" >> a
> +  $ hg ci -d "`date +'%b %d'`" -m "today is a good day to code"
> +  $ hg log -d today --template '{desc}\n'
> +  today is a good day to code
> +  $ echo "goodbye" >> a
> +  $ hg ci -d "`date +'%b'` $((`date +'%d'` - 1))" -m "the time traveler's code"
> +  $ hg log -d yesterday --template '{desc}\n'
> +  the time traveler's code

Perhaps this could be tested with debugdate instead, or possibly a docstring
(see http://mercurial.selenic.com/wiki/WritingTests).

You should also add some documentation at mercurial/help/dates.txt .

Thanks!
Wagner
Augie Fackler - Jan. 23, 2013, 3:01 p.m.
On Tue, Jan 22, 2013 at 04:28:04PM -0800, Paul Cavallaro wrote:
> # HG changeset patch
> # User Paul Cavallaro <ptc@fb.com>
> # Date 1358900012 28800
> # Node ID 1ad84126894a6d1127a7098b605df797f9e49c12
> # Parent  1f794204abbd7dd4bc329ae0c7c4fd7ce56b33af
> util: parsedate: Update to understand 'today' and 'yesterday' (issue 3764)
> ***
> Adding support for "today" and "yesterday" to parsedate
>
> Test Plan: Use `./hg log -d today` or another command

Looks like some cruft from a previous round of these and either a
qfold or a histedit?

As Wagner mentioned, this will likely need to wait for after the code
freeze is done.

>
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -1035,6 +1035,13 @@
>      if not formats:
>          formats = defaultdateformats
>      date = date.strip()
> +
> +    if date == 'today':
> +        date = datetime.date.today().strftime('%b %d')
> +    elif date == 'yesterday':
> +        date = (datetime.date.today() -
> +                datetime.timedelta(days=1)).strftime('%b %d')
> +
>      try:
>          when, offset = map(int, date.split(' '))
>      except ValueError:
> 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
> @@ -234,3 +234,13 @@
>    Sat Apr 15 13:30:00 2006 +0000
>    Wed Feb 01 13:00:30 2006 -0500
>    Wed Feb 01 13:00:30 2006 +0000
> +
> +Test issue 3764 (interpreting 'today' and 'yesterday')
> +  $ echo "hello" >> a
> +  $ hg ci -d "`date +'%b %d'`" -m "today is a good day to code"
> +  $ hg log -d today --template '{desc}\n'
> +  today is a good day to code
> +  $ echo "goodbye" >> a
> +  $ hg ci -d "`date +'%b'` $((`date +'%d'` - 1))" -m "the time traveler's code"

I feel like $(( )) is a bashism (and my brief experiment in dash
suggests my memory isn't totally crazy. Can you do this with some
inline Python (search for >>> in a .t file if you need an example)
instead of the shell tricks?

> +  $ hg log -d yesterday --template '{desc}\n'
> +  the time traveler's code
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Julien Cristau - Jan. 23, 2013, 4:09 p.m.
On Tue, Jan 22, 2013 at 16:28:04 -0800, Paul Cavallaro wrote:

> +  $ hg ci -d "`date +'%b'` $((`date +'%d'` - 1))" -m "the time traveler's code"

What if `date +%d` is 1?

Cheers,
Julien
Bryan O'Sullivan - Jan. 23, 2013, 5:05 p.m.
On Tue, Jan 22, 2013 at 4:28 PM, Paul Cavallaro <ptc@fb.com> wrote:

> util: parsedate: Update to understand 'today' and 'yesterday' (issue 3764)
>

A better first line would be:

util: make parsedate support 'today' and 'yesterday' (issue3764)

This follows the patch description
guidelines<http://mercurial.selenic.com/wiki/ContributingChanges#Patch_descriptions>
.

Adding support for "today" and "yesterday" to parsedate
>
> Test Plan: Use `./hg log -d today` or another command
>

These lines are superfluous.

Otherwise, Augie and Wagner's suggestion of using inline Python to deal
with dates instead of bash sytax sounds great.
Matt Mackall - Jan. 23, 2013, 5:44 p.m.
On Wed, 2013-01-23 at 09:05 -0800, Bryan O'Sullivan wrote:
> On Tue, Jan 22, 2013 at 4:28 PM, Paul Cavallaro <ptc@fb.com> wrote:
> 
> > util: parsedate: Update to understand 'today' and 'yesterday' (issue 3764)
> >
> 
> A better first line would be:
> 
> util: make parsedate support 'today' and 'yesterday' (issue3764)

I suggest:

dates: support 'today' and 'yesterday' in parsedate (issue3764)

The first word is supposed to be "the most useful topic keyword", which
is often not the module name. Like commands, util is too much of a grab
bag to be very useful here.
Paul Cavallaro - Jan. 23, 2013, 6:47 p.m.
Hey All,

Thanks for the comments! I've incorporated them, and could send off another patch bomb, or try to inline them here, although not sure about the appropriate course of action, since this won't be accepted/considered until at least Feb 1st.

The doctests info seems to be a little outdated on the wiki: http://mercurial.selenic.com/wiki/WritingTests#Writing_a_Python_doctest

Notably, tests/test-docstring.py does not exist, and I'm not sure what it's trying to reference. I had to do some hacks around importing posix from util.py because it seems like all the imports are package relative?

Anyways, let me know what if I should hold off on this patch tip February 1st, or if it's okay to patch bomb it, and then just ping it again once the time has come.

Thanks,

-Paul

On Jan 23, 2013, at 9:44 AM, Matt Mackall <mpm@selenic.com<mailto:mpm@selenic.com>>
 wrote:

On Wed, 2013-01-23 at 09:05 -0800, Bryan O'Sullivan wrote:
On Tue, Jan 22, 2013 at 4:28 PM, Paul Cavallaro <ptc@fb.com<mailto:ptc@fb.com>> wrote:

util: parsedate: Update to understand 'today' and 'yesterday' (issue 3764)


A better first line would be:

util: make parsedate support 'today' and 'yesterday' (issue3764)

I suggest:

dates: support 'today' and 'yesterday' in parsedate (issue3764)

The first word is supposed to be "the most useful topic keyword", which
is often not the module name. Like commands, util is too much of a grab
bag to be very useful here.

--
Mathematics is the supreme nostalgia of our time.
Matt Mackall - Jan. 23, 2013, 6:57 p.m.
On Wed, 2013-01-23 at 18:47 +0000, Paul Cavallaro wrote:
> Hey All,
> 
> 
> Thanks for the comments! I've incorporated them, and could send off
> another patch bomb, or try to inline them here, although not sure
> about the appropriate course of action, since this won't be
> accepted/considered until at least Feb 1st.

Best to wait.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1035,6 +1035,13 @@ 
     if not formats:
         formats = defaultdateformats
     date = date.strip()
+
+    if date == 'today':
+        date = datetime.date.today().strftime('%b %d')
+    elif date == 'yesterday':
+        date = (datetime.date.today() -
+                datetime.timedelta(days=1)).strftime('%b %d')
+
     try:
         when, offset = map(int, date.split(' '))
     except ValueError:
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
@@ -234,3 +234,13 @@ 
   Sat Apr 15 13:30:00 2006 +0000
   Wed Feb 01 13:00:30 2006 -0500
   Wed Feb 01 13:00:30 2006 +0000
+
+Test issue 3764 (interpreting 'today' and 'yesterday')
+  $ echo "hello" >> a
+  $ hg ci -d "`date +'%b %d'`" -m "today is a good day to code"
+  $ hg log -d today --template '{desc}\n'
+  today is a good day to code
+  $ echo "goodbye" >> a
+  $ hg ci -d "`date +'%b'` $((`date +'%d'` - 1))" -m "the time traveler's code"
+  $ hg log -d yesterday --template '{desc}\n'
+  the time traveler's code