#26281: utils.formats.date_format() does not work with datetime.date
-------------------------------+--------------------
Reporter: flesser | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
When using `date_format()` on a `datetime.date` object, I get the
following error:
{{{
File "<project>/<app>/models.py" in __str__
104. return date_format(self.date, format="%A, %d.%m.%Y")
File "<project>/env/lib/python3.4/site-packages/django/utils/formats.py"
in date_format
151. return dateformat.format(value, get_format(format or
'DATE_FORMAT', use_l10n=use_l10n))
File "<project>/env/lib/python3.4/site-
packages/django/utils/dateformat.py" in format
367. return df.format(format_string)
File "<project>/env/lib/python3.4/site-
packages/django/utils/dateformat.py" in format
37. pieces.append(force_text(getattr(self, piece)()))
File "<project>/env/lib/python3.4/site-
packages/django/utils/dateformat.py" in A
66. if self.data.hour > 11:
Exception Type: AttributeError at /
Exception Value: 'datetime.date' object has no attribute 'hour'
}}}
It seems to expect a `datetime.datetime`object, while the docstring for
`date_format()` explicitly mentions `datetime.date` as a valid input, too:
''"Formats a datetime.date or datetime.datetime object using a localizable
format"''.
'''How to reproduce:'''
models.py:
{{{
from django.db import models
from django.utils.formats import date_format
class ArrivalDate(models.Model):
date = models.DateField()
def __str__(self):
return date_format(self.date, format="%A, %d.%m.%Y")
}}}
template.html:
{{{
the date is {{ arrivaldate_instance }}
}}}
settings.py:
{{{
LANGUAGE_CODE = 'de-de'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
}}}
I'm running Django 1.9.2 on Python 3.4
--
Ticket URL: <https://code.djangoproject.com/ticket/26281>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.8827e4586af5e28a1d856eef83c0c65c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.