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

Don't store timezone as tzinfo.tzname #36

Closed
alanhamlett opened this issue Sep 29, 2013 · 1 comment
Closed

Don't store timezone as tzinfo.tzname #36

alanhamlett opened this issue Sep 29, 2013 · 1 comment

Comments

@alanhamlett
Copy link

This causes problems when using last_* methods off the Delorean, for example:

>>> import pytz
>>> from delorean import Delorean
>>> from datetime import datetime, timedelta
>>> pdt = pytz.timezone('America/Los_Angeles')
>>> dt = datetime.utcnow()
>>> dt = pdt.normalize(pytz.utc.localize(dt))
>>> delorean = Delorean(datetime=dt)
>>> delorean.last_week()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/blue/git/wakatime/venv/local/lib/python2.7/site-packages/delorean/dates.py", line 267, in _shift_date
    return Delorean(datetime=dt.replace(tzinfo=None), timezone=self._tz)
  File "/home/blue/git/wakatime/venv/local/lib/python2.7/site-packages/delorean/dates.py", line 198, in __init__
    self._dt = localize(datetime, timezone)
  File "/home/blue/git/wakatime/venv/local/lib/python2.7/site-packages/delorean/dates.py", line 141, in localize
    tz = timezone(tz)
  File "/home/blue/git/wakatime/venv/local/lib/python2.7/site-packages/pytz/__init__.py", line 182, in timezone
    raise UnknownTimeZoneError(zone)
pytz.exceptions.UnknownTimeZoneError: 'PDT'
@swistakm
Copy link
Contributor

This also happens when you create Delorean from others Delorean's datetime if timezone is different than UTC:

>>> import delorean
>>> d1 = delorean.Delorean(timezone='America/Chicago')
>>> d2 = delorean.Delorean(d1.datetime)
>>> d1.next_day(1)
Delorean(datetime=2013-10-24 05:28:02.624143-05:00, timezone=America/Chicago)
>>> d2.next_day(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/swistakm/dev/env-tebe-packets/local/lib/python2.7/site-packages/delorean/dates.py", line 311, in next_day
    return Delorean(datetime=dt, timezone=self._tz)
  File "/home/swistakm/dev/env-tebe-packets/local/lib/python2.7/site-packages/delorean/dates.py", line 198, in __init__
    self._dt = localize(datetime, timezone)
  File "/home/swistakm/dev/env-tebe-packets/local/lib/python2.7/site-packages/delorean/dates.py", line 141, in localize
    tz = timezone(tz)
  File "/home/swistakm/dev/env-tebe-packets/local/lib/python2.7/site-packages/pytz/__init__.py", line 180, in timezone
    raise UnknownTimeZoneError(zone)
pytz.exceptions.UnknownTimeZoneError: 'CDT'
>>> 

myusuf3 pushed a commit that referenced this issue Nov 5, 2013
myusuf3 added a commit that referenced this issue Nov 5, 2013
@myusuf3 myusuf3 closed this as completed Dec 16, 2013
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

No branches or pull requests

3 participants