-
Notifications
You must be signed in to change notification settings - Fork 148
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
The package (wrongly) assumes all times are in the local timezone #55
Comments
Can you provide example failures and expected results? |
The issue seems to be the A solution might be to allow the caller to pass in the 'now' time. On Python 3.5: >>> import datetime
>>> import humanize
# parse a timestamp with utc offset
>>> ts = datetime.datetime.strptime("2018-02-15T21:31:16.048820-0800", "%Y-%m-%dT%H:%M:%S.%f%z")
>>> ts
datetime.datetime(2018, 2, 15, 21, 31, 16, 48820, tzinfo=datetime.timezone(datetime.timedelta(-1, 57600)))
>>> humanize.naturaltime(ts)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/akipp/.virtualenvs/lucid-kube/lib/python3.5/site-packages/humanize/time.py", line 116, in naturaltime
date, delta = date_and_delta(value)
File "/Users/akipp/.virtualenvs/lucid-kube/lib/python3.5/site-packages/humanize/time.py", line 30, in date_and_delta
delta = now - value
TypeError: can't subtract offset-naive and offset-aware datetimes``` |
Another solution would be to allow the caller to pass in tzinfo struct and localize the "now" time to that tz. |
No description provided.
The text was updated successfully, but these errors were encountered: