Skip to content

Commit

Permalink
naturaldate now appends a year when ±5 months
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Feb 14, 2020
1 parent 22a0a13 commit 1afc39e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/humanize/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ def naturalday(value, format="%b %d"):


def naturaldate(value):
"""Like naturalday, but will append a year for dates that are a year
ago or more."""
"""Like naturalday, but append a year for dates more than about five months away.
"""
try:
value = dt.date(value.year, value.month, value.day)
except AttributeError:
Expand All @@ -207,6 +207,6 @@ def naturaldate(value):
# Date arguments out of range
return value
delta = abs_timedelta(value - dt.date.today())
if delta.days >= 365:
if delta.days >= 5 * 365 / 12:
return naturalday(value, "%b %d %Y")
return naturalday(value)
26 changes: 13 additions & 13 deletions tests/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@ def test_naturalday(test_args, expected):
(VALUE_ERROR_TEST, VALUE_ERROR_TEST),
(OVERFLOW_ERROR_TEST, OVERFLOW_ERROR_TEST),
(dt.date(2019, 2, 2), "Feb 02 2019"),
(dt.date(2019, 3, 2), "Mar 02"),
(dt.date(2019, 4, 2), "Apr 02"),
(dt.date(2019, 5, 2), "May 02"),
(dt.date(2019, 6, 2), "Jun 02"),
(dt.date(2019, 7, 2), "Jul 02"),
(dt.date(2019, 8, 2), "Aug 02"),
(dt.date(2019, 9, 2), "Sep 02"),
(dt.date(2019, 3, 2), "Mar 02 2019"),
(dt.date(2019, 4, 2), "Apr 02 2019"),
(dt.date(2019, 5, 2), "May 02 2019"),
(dt.date(2019, 6, 2), "Jun 02 2019"),
(dt.date(2019, 7, 2), "Jul 02 2019"),
(dt.date(2019, 8, 2), "Aug 02 2019"),
(dt.date(2019, 9, 2), "Sep 02 2019"),
(dt.date(2019, 10, 2), "Oct 02"),
(dt.date(2019, 11, 2), "Nov 02"),
(dt.date(2019, 12, 2), "Dec 02"),
Expand All @@ -331,12 +331,12 @@ def test_naturalday(test_args, expected):
(dt.date(2020, 5, 2), "May 02"),
(dt.date(2020, 6, 2), "Jun 02"),
(dt.date(2020, 7, 2), "Jul 02"),
(dt.date(2020, 8, 2), "Aug 02"),
(dt.date(2020, 9, 2), "Sep 02"),
(dt.date(2020, 10, 2), "Oct 02"),
(dt.date(2020, 11, 2), "Nov 02"),
(dt.date(2020, 12, 2), "Dec 02"),
(dt.date(2021, 1, 2), "Jan 02"),
(dt.date(2020, 8, 2), "Aug 02 2020"),
(dt.date(2020, 9, 2), "Sep 02 2020"),
(dt.date(2020, 10, 2), "Oct 02 2020"),
(dt.date(2020, 11, 2), "Nov 02 2020"),
(dt.date(2020, 12, 2), "Dec 02 2020"),
(dt.date(2021, 1, 2), "Jan 02 2021"),
(dt.date(2021, 2, 2), "Feb 02 2021"),
],
)
Expand Down

0 comments on commit 1afc39e

Please sign in to comment.