Closed
Labels
bugSomething isn't workingSomething isn't working
Description
What did you do?
If I pass 32399 seconds to precisedelta (8 hours 59 minutes 59 seconds) and set minimum time to minutes, it does not round up to hours. That is, it will round 59 minutes 59 seconds to 60 minutes but doesn't take the step further to round 60 minutes to hours.
What did you expect to happen?
'9 hours'
What actually happened?
'8 hours and 60 minutes'
What versions are you using?
- OS: Debian 4.19
- Python: 3.73
- Humanize: 4.22
Please include code that reproduces the issue.
import humanize
humanize.precisedelta(32399, minimum_unit='minutes', format='%0.0f')Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
eldipa commentedon Jul 7, 2022
Hi @ralkire, let me show you step by step what is happening.
Indeed the
32399is not"9 hours"but one second before. The idea ofprecisedeltais to preserve the precision and do not do any rounding unless it is explicitly requested.Now, let's add
minimum_unit:Once again
precisedeltapreserves the precision. Because the delta cannot be represented by an integer number of minutes,precisedeltaformats it asfloat. Remember that32399is not"9 hours"so doing a rounding would be incorrect.Finally, let's add the format:
It looks unusual, yes, but why is happening. The issue is not in
precisedeltabut in the format'%0.0f'.The
59.98 minutesis formatted with'%0.0f'and this is literally saying that the float number must be rounded to have 0 digits after the dot.That's why
59.98goes to60. It is an artifact of the formatting, not of the calculation.webdeck commentedon Sep 1, 2023
Similar issue with seeing incorrect plurals when using a format of "%0.0f":