Skip to content

Comments

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

Open
magopian wants to merge 2 commits intoliberation:masterfrom
magopian:django-1.4
Open

Django1.4 with USE_TZ=True needs timezone aware datetimes#2
magopian wants to merge 2 commits intoliberation:masterfrom
magopian:django-1.4

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

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