-
-
Notifications
You must be signed in to change notification settings - Fork 691
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
Strange Timezone offset #1207
Comments
@hasandiwan The difference you're experiencing is due to a very minor delta between when the For example, if you print both timestamps, you'll notice a small difference (around 59 milliseconds) between them.
|
The difference in days between utcnow and now, given that I'm in PST8PDT, should not be -1. |
The reason you're getting such a strange result is probably due to the quirk of how >>> timedelta(seconds=-1)
datetime.timedelta(days=-1, seconds=86399) the |
Seems unlikely that an 8 hour time difference would be less than a second. |
It's always frustrating when code does something unexpected. Try running each part of the code one-by-one to see where the surprising result comes from 🙂. edit: the result of both the statements is aware, and thus the result is measured in absolute terms. So a few milliseconds seems likely |
% env TZ=PST8PDT ~/.virtualenvs/data/bin/ipython In [1]: from arrow import Arrow In [2]: (Arrow.utcnow()-Arrow.now()).total_seconds() |
Note: if you want the UTC offset of the local timezone at the current moment, just do: >>> arrow.now().utcoffset().total_seconds() Now on to why your earlier result isn't expected. >>> a = arrow.utcnow()
<Arrow [2025-01-20T20:45:18.461830+00:00]>
>>> b = arrow.now()
<Arrow [2025-01-20T21:45:20.316133+01:00]> The subtraction operator determines the difference in absolute terms—i.e. as if both datetimes were normalized to UTC. If you want to compare datetimes "naively", use the (a.naive - b.naive).total_seconds() |
Issue Description
3.11
In [3]: arrow.version
Out[3]: '1.3.0'
The text was updated successfully, but these errors were encountered: