-
-
Notifications
You must be signed in to change notification settings - Fork 684
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
arrow.get(datetime.now()).humanize() == "6 hours ago" #944
Comments
Hey @zachriggle there definitely looks to be some weirdness going on with the tzinfo setting here. I will investigate this further. Two other points, Arrow objects are never naive, they default to UTC if no tzinfo is provided. Also |
The problem is that the (arrow) chris@Z490:~/arrow$ python
Python 3.9.1 (default, Feb 17 2021, 16:56:42)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> import datetime
>>> arrow.get(datetime.datetime.now(), tzinfo="America/Chicago")
<Arrow [2021-03-17T21:33:42.404027+00:00]>
>>> arrow.get(datetime.datetime.now(), tzinfo="America/Chicago").tzinfo
tzutc() It defaults to UTC which causes strange results. The bug is in https://github.com/arrow-py/arrow/blob/master/arrow/factory.py#L241 where the |
Glad you found the culprit! I eagerly await a new Arrow release.
I can't contribute to FOSS (employer rules) otherwise I'd create the PR
myself.
…On Wed, Mar 17, 2021 at 4:47 PM Chris ***@***.***> wrote:
The problem is that the tzinfo supplied to arrow.get() is being ignored
in certain cases, for example:
(arrow) ***@***.***:~/arrow$ python
Python 3.9.1 (default, Feb 17 2021, 16:56:42)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> import datetime
>>> arrow.get(datetime.datetime.now(), tzinfo="America/Chicago")<Arrow [2021-03-17T21:33:42.404027+00:00]>
>>> arrow.get(datetime.datetime.now(), tzinfo="America/Chicago").tzinfotzutc()
It defaults to UTC which causes strange results.
The bug is in
https://github.com/arrow-py/arrow/blob/master/arrow/factory.py#L241 where
the tzinfo kwarg is dropped.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#944 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA3IGFWUUTAD6GGA352R5LTEEPORANCNFSM4Y45YTRQ>
.
|
Issue Description
It looks like
arrow
is doing something weird timezone information when operatingdatetime
objects, includingdatetime
objects returned by e.g.dateparser.parse('now')
.What is the appropriate incantation to get
arrow
anddatetime
to agree? I've managed to do it in one of my projects by using epochseconds, but would prefer to keep my dates as eitherdatetime
orarrow
object representations.I am in central standard time, so the "6 hours ago" seems to reflect my TZ offset from UTC, but even providing a
..., tzinfo=
does not appear to do the correct thing.Overall, the mixture of simple things that don't work is overwhelming, and there should maybe be some examples in the documentation for how to do this right (e.g. setting tzinfo on the datetime object makes arrow's object correct, but setting tzinfo on the arrow object does not).
date(1) vs datetime
As best I can tell,
datetime.now()
is correct, and lacks a specific timezone.datetime vs arrow
This jives with the 6 hour time difference from UTC, but why does it say "6 hours ago"? Neither arrow nor datetime were provided with a timezone, so this seems odd.
datetime with tzinfo
This happens even with a custom timezone, unless the timezone is specified on the datetime object.
dateparser
Per the documentation:
However, this doesn't seem to work correctly either.
dateparser with tzinfo
This happens regardless of whether
tzinfo
is specified.Unix Timestamps
It looks like there's an issue with timestamps as well. If I pass the timestamp directly to
arrow.get()
, it returns the correct value.System Info
The text was updated successfully, but these errors were encountered: