Refs #26281 -- Added a helpful error message for an invalid "r" specifier to dateformat.format().
This commit is contained in:
parent
379bf1a2d4
commit
76ec032712
|
@ -278,6 +278,11 @@ class DateFormat(TimeFormat):
|
|||
|
||||
def r(self):
|
||||
"RFC 5322 formatted date; e.g. 'Thu, 21 Dec 2000 16:01:07 +0200'"
|
||||
if type(self.data) is datetime.date:
|
||||
raise TypeError(
|
||||
"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')
|
||||
|
||||
def S(self):
|
||||
|
|
|
@ -149,7 +149,7 @@ class DateFormatTests(SimpleTestCase):
|
|||
def test_invalid_time_format_specifiers(self):
|
||||
my_birthday = date(1984, 8, 7)
|
||||
|
||||
for specifier in ['a', 'A', 'f', 'g', 'G', 'h', 'H', 'i', 'P', 's', 'u']:
|
||||
for specifier in ['a', 'A', 'f', 'g', 'G', 'h', 'H', 'i', 'P', 'r', 's', 'u']:
|
||||
msg = (
|
||||
"The format for date objects may not contain time-related "
|
||||
"format specifiers (found '%s')." % specifier
|
||||
|
|
Loading…
Reference in New Issue