You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Hi @ralkire, let me show you step by step what is happening.
>>>importhumanize>>>humanize.precisedelta(32399)
'8 hours, 59 minutes and 59 seconds'
Indeed the 32399 is not"9 hours" but one second before. The idea of precisedelta is to preserve the precision and do not do any rounding unless it is explicitly requested.
Now, let's add minimum_unit:
>>>humanize.precisedelta(32399, minimum_unit='minutes')
'8 hours and 59.98 minutes'
Once again precisedelta preserves the precision. Because the delta cannot be represented by an integer number of minutes, precisedelta formats it as float. Remember that 32399 is not"9 hours" so doing a rounding would be incorrect.
Finally, let's add the format:
>>>humanize.precisedelta(32399, minimum_unit='minutes', format='%0.0f')
'8 hours and 60 minutes'
It looks unusual, yes, but why is happening. The issue is not in precisedelta but in the format '%0.0f'.
The 59.98 minutes is 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.98 goes to 60. It is an artifact of the formatting, not of the calculation.
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?
Please include code that reproduces the issue.
The text was updated successfully, but these errors were encountered: