Skip to content

Commit

Permalink
NEW: Use humanize.intcomma to format years in time module
Browse files Browse the repository at this point in the history
  • Loading branch information
carterbox committed Dec 3, 2021
1 parent 429e3d8 commit d1faf1c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/humanize/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from .i18n import _gettext as _
from .i18n import _ngettext
from .number import intcomma

__all__ = [
"naturaldelta",
Expand Down Expand Up @@ -264,7 +265,7 @@ def naturaldelta(
else:
return _ngettext("1 year, %d day", "1 year, %d days", days) % days
else:
return _ngettext("%d year", "%d years", years) % years
return _ngettext("%s year", "%s years", years) % intcomma(years)


def naturaltime(
Expand Down Expand Up @@ -605,6 +606,10 @@ def precisedelta(value, minimum_unit="seconds", suppress=(), format="%0.2f") ->
fmt_txt = _ngettext(singular_txt, plural_txt, value)
if unit == min_unit and math.modf(value)[0] > 0:
fmt_txt = fmt_txt.replace("%d", format)
elif unit == YEARS:
fmt_txt = fmt_txt.replace("%d", "%s")
texts.append(fmt_txt % intcomma(value))
continue

texts.append(fmt_txt % value)

Expand Down

0 comments on commit d1faf1c

Please sign in to comment.