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.
* cc: f.esser@… (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26281#comment:1>
* component: Uncategorized => Utilities
* stage: Unreviewed => Accepted
* type: Bug => Cleanup/optimization
Comment:
You can't use `%A` (which corresponds to AM/PM) with a date. I guess you
were looking at Python's formatting characters where that corresponds to
"Weekday as locale’s full name".
Accepting on the basis that it might be feasible to improve the error
message.
--
Ticket URL: <https://code.djangoproject.com/ticket/26281#comment:2>
Comment (by flesser):
I indeed was expecting to use Python's formatting characters in a Python
project.
Using PHP's formatting characters instead (`format="l, d.m.Y"`) as
[https://docs.djangoproject.com/es/1.9/ref/templates/builtins/#date
documented here] gives me the result I was looking for.
Considering the method is intended for use in a Twig-like template
environment, the design decision to make it PHP compatible seems
reasonable. But mentioning that in the docstring and the error message
would help to prevent misunderstandings like mine.
--
Ticket URL: <https://code.djangoproject.com/ticket/26281#comment:3>
* owner: nobody => benxy
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/26281#comment:4>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/6407 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/26281#comment:5>
* needs_better_patch: 0 => 1
Comment:
Left some comments for improvement.
--
Ticket URL: <https://code.djangoproject.com/ticket/26281#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"45c7acdc507d26451f3c3f22b5d60bdd6d572cfc" 45c7acdc]:
{{{
#!CommitTicketReference repository=""
revision="45c7acdc507d26451f3c3f22b5d60bdd6d572cfc"
Fixed #26281 -- Added a helpful error message for an invalid format
specifier to dateformat.format().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26281#comment:7>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"76ec032712d28dd8d4b9ad425f2b330a3e9a9109" 76ec032]:
{{{
#!CommitTicketReference repository=""
revision="76ec032712d28dd8d4b9ad425f2b330a3e9a9109"
Refs #26281 -- Added a helpful error message for an invalid "r" specifier
to dateformat.format().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26281#comment:8>