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

Django1.4 with USE_TZ=True needs timezone aware datetimes #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

magopian
Copy link

If using Django1.4 and USE_TZ = True, the datetime objects used need to be timezone aware.

Using the django.utils.timezone helpers makes it usable wether the USE_TZ setting is set to True or False.

@magopian
Copy link
Author

Second commit "uglifies" the code, but makes it compatible with 1.3.1 AND 1.4

from django.utils.timezone import utc
return datetime.datetime(year=2008, month=7, day=1, tzinfo=utc)
except ImportError:
return datetime.datetime(year=2008, month=7, day=1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about something like:

try:
    from django.utils.timezone import utc
except ImportError:
    utc = None
return datetime.datetime(year=2008, month=7, day=1, tzinfo=utc)

I mean:

  • same call to datetime.datetime()
  • ability to move the try/import/except to the beginning of the module ?

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

Successfully merging this pull request may close these issues.

2 participants