Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

naturaltime should support timezone-aware datetimes #17

Closed
snarfed opened this issue May 10, 2022 · 0 comments · Fixed by #100
Closed

naturaltime should support timezone-aware datetimes #17

snarfed opened this issue May 10, 2022 · 0 comments · Fixed by #100

Comments

@snarfed
Copy link

snarfed commented May 10, 2022

Hi all! Reopening this one here: naturaltime currently breaks on timezone-aware datetime input values, eg with tzinfo set. Lots of background and details in jmoiron/humanize#9, jmoiron/humanize#190, and jmoiron/humanize#22, among others.

Example stacktrace below. Reproduces on the latest released version, 4.1.0. Thank you for maintaining humanize, it's great!

>>> from datetime import datetime, timezone
>>> from humanize import naturaltime
>>> naturaltime(datetime.now(timezone.utc))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ryan/src/bridgy/local/lib/python3.9/site-packages/humanize/time.py", line 231, in naturaltime
    date, delta = _date_and_delta(value, now=now)
  File "/Users/ryan/src/bridgy/local/lib/python3.9/site-packages/humanize/time.py", line 71, in _date_and_delta
    delta = now - value
TypeError: can't subtract offset-naive and offset-aware datetimes
@snarfed snarfed changed the title Support timezone-aware datetimes naturaltime should support timezone-aware datetimes May 10, 2022
snarfed added a commit to snarfed/webutil that referenced this issue May 10, 2022
...to support timezone-aware datetimes, since humanize still doesn't. :/ python-humanize/humanize#17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant