Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for timezones (new in Django 1.4).
From Django 1.4 onwards, settings.USE_TZ = True is the default for new projects. It makes sense to run the tests with this setting. Warnings related to time zones support are turned into exceptions to make debugging easier and prevent regressions in this area.
- Loading branch information
Showing
9 changed files
with
74 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# This file is a partial copy of django.utils.timezone as of Django 1.4. | ||
# It must be removed as soon as django-cms drops support for Django 1.3. | ||
# All imports of cms.utils.timezone must be replaced by django.utils.timezone. | ||
|
||
from datetime import datetime, timedelta, tzinfo | ||
from threading import local | ||
|
||
try: | ||
import pytz | ||
except ImportError: | ||
pytz = None | ||
|
||
from django.conf import settings | ||
|
||
ZERO = timedelta(0) | ||
|
||
class UTC(tzinfo): | ||
""" | ||
UTC implementation taken from Python's docs. | ||
Used only when pytz isn't available. | ||
""" | ||
|
||
def __repr__(self): | ||
return "<UTC>" | ||
|
||
def utcoffset(self, dt): | ||
return ZERO | ||
|
||
def tzname(self, dt): | ||
return "UTC" | ||
|
||
def dst(self, dt): | ||
return ZERO | ||
|
||
utc = pytz.utc if pytz else UTC() | ||
"""UTC time zone as a tzinfo instance.""" | ||
|
||
def now(): | ||
""" | ||
Returns an aware or naive datetime.datetime, depending on settings.USE_TZ. | ||
""" | ||
if settings.USE_TZ: | ||
# timeit shows that datetime.now(tz=utc) is 24% slower | ||
return datetime.utcnow().replace(tzinfo=utc) | ||
else: | ||
return datetime.now() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters