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

Wagner Bruna wagner.bruna+mercurial at gmail.com
Wed Jan 23 08:48:30 CST 2013


Em 22-01-2013 22:28, Paul Cavallaro escreveu:
> # HG changeset patch
> # User Paul Cavallaro <ptc at 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


More information about the Mercurial-devel mailing list