diff options
| author | Baptiste Mispelon <bmispelon@gmail.com> | 2019-11-21 20:34:58 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-11-22 12:41:53 +0100 |
| commit | 8929afb8ec4bc2bfb95b66c05fc3ab39e3748d91 (patch) | |
| tree | bab999ca075bfa3682a6aeac0b6a736848e7c022 /django/utils/dateformat.py | |
| parent | 76ec032712d28dd8d4b9ad425f2b330a3e9a9109 (diff) | |
Fixed #9762 -- Made DateFormat.r() locale-independent.
Thanks to Antonio Melé for the original report all those years ago
and to all the contributors who helped along the way.
Diffstat (limited to 'django/utils/dateformat.py')
| -rw-r--r-- | django/utils/dateformat.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py index 5bde2680b8..7a8c83af09 100644 --- a/django/utils/dateformat.py +++ b/django/utils/dateformat.py @@ -13,12 +13,15 @@ Usage: import calendar import datetime import time +from email.utils import format_datetime as format_datetime_rfc5322 from django.utils.dates import ( MONTHS, MONTHS_3, MONTHS_ALT, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR, ) from django.utils.regex_helper import _lazy_re_compile -from django.utils.timezone import get_default_timezone, is_aware, is_naive +from django.utils.timezone import ( + get_default_timezone, is_aware, is_naive, make_aware, +) from django.utils.translation import gettext as _ re_formatchars = _lazy_re_compile(r'(?<!\\)([aAbcdDeEfFgGhHiIjlLmMnNoOPrsStTUuwWyYzZ])') @@ -283,7 +286,11 @@ class DateFormat(TimeFormat): "The format for date objects may not contain time-related " "format specifiers (found 'r')." ) - return self.format('D, j M Y H:i:s O') + if is_naive(self.data): + dt = make_aware(self.data, timezone=self.timezone) + else: + dt = self.data + return format_datetime_rfc5322(dt) def S(self): "English ordinal suffix for the day of the month, 2 characters; i.e. 'st', 'nd', 'rd' or 'th'" |
