humanize
humanize copied to clipboard
`humanize.naturaldelta()` always rounds down
What did you do?
import humanize
humanize.naturaldelta(10799)
Note that this is exactly one second below 3 hours.
What did you expect to happen?
It should say 3 hours.
What actually happened?
It says 2 hours.
What versions are you using?
- OS: Debian 12
- Python: 3.11.2
- Humanize: 4.9.0
Please include code that reproduces the issue.
The best reproductions are self-contained scripts with minimal dependencies.
import humanize
print(humanize.naturaldelta(10800)) # "3 hours"
print(humanize.naturaldelta(10799)) # "2 hours"
Previously reported at the old repo:
- https://github.com/jmoiron/humanize/issues/116
- https://github.com/jmoiron/humanize/issues/186
- https://github.com/jmoiron/humanize/issues/143
But those are closed, so we let's use this new issue.
There's an old PR that started work to fix this, but was never finished:
- https://github.com/jmoiron/humanize/pull/154
Just ran into this, too. precisedelta(mydtime) -> '12 hours, 51 minutes and 44.17 seconds' naturaldelta(mydtime) -> '12 hours'. 🤐
@hugovk I'd possibly be motivated to pick this up. What's still needed over the old solution?
@mmarras That would be great! I don't remember by now, https://github.com/jmoiron/humanize/pull/154/commits/a75d18cb109012b5ebc94ae0aaf976a743c581f2 was the main commit, the others in the PR were mostly cosmetic and some have already been applied. At least the Unit -> _Unit renaming should be skipped. And it might be better with a fresh start, but feel free to take anything useful, like the tests might be.