question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

humanize overflows before datetime does

See original GitHub issue

What did you do?

I tried to humanize a very long time.

What did you expect to happen?

I expect the time to be converted into years/millenia/eon if it is within the bounds of datetime i.e. <= 999 999 999 days, and if the number is higher than that or uncountable with the compute platform (64/32 bits) then something like “longer than countable”.

At the very least, this type of error should be handled like others in _date_and_delta: the timedelta is returned unaltered.

What actually happened?

I received an overflow error from an operation within humanize.

What versions are you using?

  • OS: Ubuntu x64
  • Python: 3.9.6
  • Humanize: 3.13.1

Please include code that reproduces the issue.

The best reproductions are self-contained scripts with minimal dependencies.

import datetime as dt
import humanize
d = dt.timedelta(days=999999999)
print(d)
h = humanize.naturaldelta(d)
print(h)
# ... e/time.py", line 131, in _date_and_delta
#    date = now - value
# OverflowError: date value out of range

Once we discuss how to best handle this error, I’d be happy to open a PR.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
carterboxcommented, Dec 15, 2021

To summarize: the original issue is that an OverflowError is raised by naturaldelta() at deltas much smaller than what datetime can handle. Other errors in naturaldelta() cause a timedelta to be returned instead of a string, but this is undocumented. We want to retain the current behavior (to raise errors sometimes, return string sometimes, and return timedelta sometimes), but we want to document when each of these outcomes occurs.

Can I still refactor naturaldelta() so that the OverflowError is raised by datetime instead of by humanize? I believe this is compatible with the approach above given the unrelated deprecation of naturaldelta(..., when).

0reactions
hugovkcommented, Dec 21, 2021

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python's humanize timedelta() tells me that minimum_unit ...
After running pip install humanize --upgrade I was able to use the precisedelta function suggested in the accepted answer. python · datetime ......
Read more >
Moment.js | Docs
Before parsing a RFC 2822 date time the string is cleansed to remove any comments and/or newline characters. The additional characters are legal...
Read more >
humanize 4.4.0
Python humanize utilities. ... /pkg/h/humanize/humanize-banner.webp ... are wrong/incomplete; humanize overflows before datetime does ...
Read more >
Date and time of an article in a humanized and localized way
Put a space after now and before = info = None. Info will always be assigned something later, there is no reason to...
Read more >
Carbon - A simple PHP API extension for DateTime.
$unixTimestamp. returns Carbon. Set the instance's timestamp. Timestamp input can be given as int, float or a string containing one or more numbers....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found