What did you do?
In [18]: humanize.naturaldelta(timedelta(days=4.6*365), months=True)
Out[18]: '4 years'
In [19]: humanize.naturaldelta(timedelta(days=4.6*365), months=False)
Out[19]: '4 years'
What did you expect to happen?
In [18]: humanize.naturaldelta(timedelta(days=4.6*365), months=True)
Out[18]: '4 years, 7 months'
In [19]: humanize.naturaldelta(timedelta(days=4.6*365), months=False)
Out[19]: '4 years'
What actually happened?
see above
What versions are you using?
- OS: x86_64 GNU/Linux
- Python: 3.11.3
- Humanize: 4.6.0
How to fix?
# Excerpt from humanize/time.py # ... more code hereelifyears==1:
ifnotnum_monthsandnotdays:
return_("a year")
ifnotnum_months:
return_ngettext("1 year, %d day", "1 year, %d days", days) %daysifuse_months:
ifnum_months==1:
return_("1 year, 1 month")
return (
_ngettext("1 year, %d month", "1 year, %d months", num_months)
%num_months
)
return_ngettext("1 year, %d day", "1 year, %d days", days) %days# TODO: Here we should check whether use_months is true and format accordingly.return_ngettext("%d year", "%d years", years).replace("%d", "%s") %intcomma(years)
What did you do?
What did you expect to happen?
What actually happened?
see above
What versions are you using?
How to fix?