Skip to content

Issues with odd months when restricting to "day" precision (precisedelta) #14

Open
@ddellspe

Description

@ddellspe

What did you do?

I'm trying to provide more precision than "months" when the timedelta is more than 1 month, but I'm finding some issues using precisedelta set to days with a format of %d as seen below. This all seems to stem from the use of 30.5 as a divisor for mod in precisedelta and how it and ngettext interact with floats vs. ints when it comes to pluralize and the display of the days itself. For what it's worth, the same thing happens at second precision with microseconds present, etc. It seems to be at the minimum_unit where this logic takes place.

What did you expect to happen?

>>> import humanize
>>> import datetime
>>> humanize.precisedelta(datetime.timedelta(days=31), minimum_unit="days", format="%d")
'1 month'
>>> 
>>> import humanize
>>> import datetime
>>> humanize.precisedelta(datetime.timedelta(days=92), minimum_unit="days", format="%d")
'3 months'
>>> 
>>> import humanize
>>> import datetime
>>> humanize.precisedelta(datetime.timedelta(days=32), minimum_unit="days", format="%d")
'1 month and 1 day'
>>>

What actually happened?

>>> import humanize
>>> import datetime
>>> humanize.precisedelta(datetime.timedelta(days=31), minimum_unit="days", format="%d")
'1 month and 0 days'
>>> 
>>> import humanize
>>> import datetime
>>> humanize.precisedelta(datetime.timedelta(days=92), minimum_unit="days", format="%d")
'3 month and 0 days'
>>> 
>>> import humanize
>>> import datetime
>>> humanize.precisedelta(datetime.timedelta(days=32), minimum_unit="days", format="%d")
'1 month and 1 days'
>>>

What versions are you using?

  • OS: Windows, Ubuntu 20.04
  • Python: 3.8.10
  • Humanize: 4.1.0

Please include code that reproduces the issue (included in expected, actually happened above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions