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
importhumanizefromdatetimeimporttimedeltaduration_seconds=1e-06# A small value, or 0delta=timedelta(seconds=duration_seconds)
output=humanize.precisedelta(delta, minimum_unit="minutes")
print(output)
What did you expect to happen?
Output would be 0 seconds.
Alternatively, a better error message or a warning in the documentation would be helpful.
What actually happened?
> tail = texts[-1]
E IndexError: list index out of range
What versions are you using?
OS: ubuntu
Python: 3.6.12
Humanize: 2.6.0
The text was updated successfully, but these errors were encountered:
What it is happening is that if the delta is in microseconds (lower than 1 second to be precise) and the minimum unit is greater than seconds (like minutes), the microseconds are not propagated to the upper units (like minutes) so it computes "0".
Because the function then ignores all the zeros (so we avoid "0 years, 0 hours, 3 secs"), the function crashes later because it deleted all the values (like "0 years, 0 hours").
The most sane fix is to catch this corner case and say "0 minutes" for example.
I left a PR with the proposed fix (sorry for the delay).
What did you do?
Calculated a small delta.
What did you expect to happen?
Output would be 0 seconds.
Alternatively, a better error message or a warning in the documentation would be helpful.
What actually happened?
What versions are you using?
The text was updated successfully, but these errors were encountered: