diff options
| author | Joachim Jablon <ewjoachim@gmail.com> | 2016-11-05 12:33:22 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-11-07 19:07:18 -0500 |
| commit | fd78fb82d633a23e04eac72c7e1f41cac75e4c5b (patch) | |
| tree | 0084edd34e533cc9b88d9071fcb541b281f6f937 /django/utils/timezone.py | |
| parent | ee1bf0e8b5f83274b7436d0a3f9240ca6c399a52 (diff) | |
Fixed #27138 -- Restored pre-Python 3.6 behavior of localtime() and make_naive() on Python 3.6.
Reverted test changes in a7a7ecd2b026c61a39a46d2d7eced0e06a92c970 and
e43ea36b7681e43ea99505a2cf7550d4d36016b3 (refs #27025).
Diffstat (limited to 'django/utils/timezone.py')
| -rw-r--r-- | django/utils/timezone.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/django/utils/timezone.py b/django/utils/timezone.py index 82c14f4f96..29885caac8 100644 --- a/django/utils/timezone.py +++ b/django/utils/timezone.py @@ -209,8 +209,9 @@ def localtime(value=None, timezone=None): value = now() if timezone is None: timezone = get_current_timezone() - # If `value` is naive, astimezone() will raise a ValueError, - # so we don't need to perform a redundant check. + # Emulate the behavior of astimezone() on Python < 3.6. + if is_naive(value): + raise ValueError("localtime() cannot be applied to a naive datetime") value = value.astimezone(timezone) if hasattr(timezone, 'normalize'): # This method is available for pytz time zones. @@ -295,8 +296,9 @@ def make_naive(value, timezone=None): """ if timezone is None: timezone = get_current_timezone() - # If `value` is naive, astimezone() will raise a ValueError, - # so we don't need to perform a redundant check. + # Emulate the behavior of astimezone() on Python < 3.6. + if is_naive(value): + raise ValueError("make_naive() cannot be applied to a naive datetime") value = value.astimezone(timezone) if hasattr(timezone, 'normalize'): # This method is available for pytz time zones. |
