diff mercurial/util.py @ 18537:ae60735e37d2

dates: support 'today' and 'yesterday' in parsedate (issue3764) Adding support to parsedate in util module to understand the more idiomatic dates 'today' and 'yesterday'. Added unified tests and docstring tests for added functionality.
author Paul Cavallaro <ptc@fb.com>
date Wed, 23 Jan 2013 09:51:45 -0800
parents 614f769e6aa7
children 2251b3184e6e
line wrap: on
line diff
--- a/mercurial/util.py	Mon Jan 28 12:19:21 2013 -0800
+++ b/mercurial/util.py	Wed Jan 23 09:51:45 2013 -0800
@@ -1027,6 +1027,14 @@
 
     The date may be a "unixtime offset" string or in one of the specified
     formats. If the date already is a (unixtime, offset) tuple, it is returned.
+
+    >>> parsedate(' today ') == parsedate(\
+                                  datetime.date.today().strftime('%b %d'))
+    True
+    >>> parsedate( 'yesterday ') == parsedate((datetime.date.today() -\
+                                               datetime.timedelta(days=1)\
+                                              ).strftime('%b %d'))
+    True
     """
     if not date:
         return 0, 0
@@ -1035,6 +1043,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: