diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-05-01 10:40:25 +0200 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-05-01 11:29:55 +0200 |
| commit | 46b082e05ccedffeb623028caf70adbaba7bce6f (patch) | |
| tree | 30c237f7767187c92690ac30c8cca4ead9023779 /django | |
| parent | 4fdd378beb81a86d826d7ee83c7d2250ed958be1 (diff) | |
Fixed #17742 -- Handled aware datetimes in DateField
Converted aware datetimes to the default time zone before using them
in the context of a DateField.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/fields/__init__.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 3e97f6cb01..79fb373ce1 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -667,6 +667,11 @@ class DateField(Field): if value is None: return value if isinstance(value, datetime.datetime): + if settings.USE_TZ and timezone.is_aware(value): + # Convert aware datetimes to the current time zone + # before casting them to dates (#17742). + default_timezone = timezone.get_default_timezone() + value = timezone.make_naive(value, default_timezone) return value.date() if isinstance(value, datetime.date): return value |
