D7520: dateutil: correct default for Ymd in parsedate

quark (Jun Wu) phabricator at mercurial-scm.org
Mon Nov 25 20:50:18 UTC 2019


quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The code uses `0` for the default value of Ymd (year, month, and day), which
  seems suboptimal. For example, these will fail to parse:
  
    dateutil.parsedate('2000', formats=dateutil.extendeddateformats)
    dateutil.parsedate('Jan 2000', formats=dateutil.extendeddateformats)
  
  Fix it by providing sane defaults (1 instead of 0) for year, month, and day.
  
  The suboptimal behavior was introduced by 91bc001a592 <https://phab.mercurial-scm.org/rHG91bc001a592fabdf3213c51a236a293037860486> (2010-12-29,
  "date: fix matching of underspecified date ranges"), which does not seem to
  justify the current behavior.
  
  Note end-users should not notice the subtle issue, because there are no formats
  in `defaultdateformats` that allow an explicit year with omitted month, or an
  explicit month with omitted day.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D7520

AFFECTED FILES
  mercurial/utils/dateutil.py

CHANGE DETAILS

diff --git a/mercurial/utils/dateutil.py b/mercurial/utils/dateutil.py
--- a/mercurial/utils/dateutil.py
+++ b/mercurial/utils/dateutil.py
@@ -209,6 +209,8 @@
     True
     >>> tz == strtz
     True
+    >>> parsedate(b'2000 UTC', formats=extendeddateformats)
+    (946684800, 0)
     """
     if bias is None:
         bias = {}
@@ -244,7 +246,8 @@
                 if part[0:1] in b"HMS":
                     b = b"00"
                 else:
-                    b = b"0"
+                    # year, month, and day start from 1
+                    b = b"1"
 
             # this piece is for matching the generic end to today's date
             n = datestr(now, b"%" + part[0:1])



To: quark, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list