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

.to() is incompatible with pytz.timezone #154

Closed
ograycode opened this issue Aug 16, 2014 · 10 comments
Closed

.to() is incompatible with pytz.timezone #154

ograycode opened this issue Aug 16, 2014 · 10 comments
Labels

Comments

@ograycode
Copy link

It looks like at least to() is incompatible with pytz.timezone. This is especially concerning because pytz is so widely used, and integrated into Django. Because of this, arrow is incompatible with djanog.utils.timezone.get_default_timezone

It is currently PDT time (offset of -7 from UTC).

In [3]: import arrow

In [4]: arrow.now()
Out[4]: <Arrow [2014-08-16T14:04:24.883067-07:00]>

In [5]: str(arrow.now().datetime)
Out[5]: '2014-08-16 14:04:37.988805-07:00'

In [6]: str(arrow.now())
Out[6]: '2014-08-16T14:04:47.148559-07:00'

In [7]: import pytz

In [10]: str(arrow.utcnow().to(pytz.timezone("America/Los_Angeles")).datetime)
Out[10]: '2014-08-16 14:10:52.073869-08:00' # Should be -7

In [11]: str(arrow.utcnow().to(pytz.timezone("America/Los_Angeles")))
Out[11]: '2014-08-16T14:11:05.067117-08:00' # Should be -7

In [12]: str(arrow.utcnow().to("America/Los_Angeles").datetime)
Out[12]: '2014-08-16 14:11:29.675558-07:00'

In [13]: str(arrow.utcnow().to("America/Los_Angeles"))
Out[13]: '2014-08-16T14:12:55.047974-07:00'

This was discovered using pytz==2014.2 and arrow==0.4.4.

@pypingou
Copy link
Contributor

I guess it is related to:

import datetime
import pytz
from dateutil import tz
n = datetime.datetime.now(tz=pytz.utc)
str(datetime.datetime(2014, 8, 17, 11, 14, 27, 796, tz.gettz('America/Los_Angeles')))
# Returns '2014-08-17 11:14:27.000796-07:00'
str(datetime.datetime(2014, 8, 17, 11, 14, 27, 796, pytz.timezone("America/Los_Angeles")))
# Returns '2014-08-17 11:14:27.000796-08:00'

@Exirel
Copy link

Exirel commented Nov 21, 2014

Yes, agree, it looks like it is related to the usage of dateutil.tz instead of relying on pytz. By the way, I reproduce the same bug with pytz==2014.9.

It's kind of annoying to be honest, and I don't really understand why pytz is not used to handle the timezone. I always considered pytz as a standard, but maybe I'm wrong?

@dekoza
Copy link

dekoza commented May 29, 2015

Any update on this?

@dekoza
Copy link

dekoza commented May 29, 2015

My results are even better:

str(arrow.utcnow().to(pytz.timezone("America/Los_Angeles")).datetime)
# Returns '2015-05-29 05:03:07.061851-07:53' # wait, what?!

pytz = 2015.2
arrow = 0.5.4

@andrewelkins
Copy link
Contributor

I'd welcome a PR to address this @dekoza @ograycode @Exirel

@ograycode
Copy link
Author

Aside from the merge conflicts, #155 resolves this but adds a dependency on pytz.

@Kudo
Copy link
Contributor

Kudo commented Aug 18, 2015

Thanks @andrewelkins's merging for #254.
If #254 did fix this issue, maybe we can further close this.
Thanks.

@ColtonProvias
Copy link

Merge on #254 also fixed issue here where offset of America/New_York was being represented as -0456 instead of -0400 after being converted from UTC. Tested on Python 3.4.3 and 3.5.0. I'd say the issue is fixed here at least.

@ograycode
Copy link
Author

Closing this issue. I never used arrow because of it, and it's being reported as fixed.

@rskumar
Copy link

rskumar commented Apr 10, 2016

Still not added in documentation? Couldn't find any example.

It would be great if someone add it in timezone specific section, as people google to find quick examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants