Fixed #3488: Added "b" option to date format filter. Thanks, Gary Wilson.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4647 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2007-02-28 16:18:55 +00:00
parent 0e683f6da4
commit 28ad156f10
3 changed files with 8 additions and 1 deletions

View File

@ -16,7 +16,7 @@ from django.utils.tzinfo import LocalTimezone
from calendar import isleap, monthrange from calendar import isleap, monthrange
import re, time import re, time
re_formatchars = re.compile(r'(?<!\\)([aABdDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])') re_formatchars = re.compile(r'(?<!\\)([aAbBdDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])')
re_escaped = re.compile(r'\\(.)') re_escaped = re.compile(r'\\(.)')
class Formatter(object): class Formatter(object):
@ -110,6 +110,10 @@ class DateFormat(TimeFormat):
if hasattr(self.data, 'hour') and not self.timezone: if hasattr(self.data, 'hour') and not self.timezone:
self.timezone = LocalTimezone(dt) self.timezone = LocalTimezone(dt)
def b(self):
"Month, textual, 3 letters, lowercase; e.g. 'jan'"
return MONTHS_3[self.data.month]
def d(self): def d(self):
"Day of the month, 2 digits with leading zeros; i.e. '01' to '31'" "Day of the month, 2 digits with leading zeros; i.e. '01' to '31'"
return '%02d' % self.data.day return '%02d' % self.data.day

View File

@ -645,6 +645,7 @@ Available format strings:
output, because this includes periods output, because this includes periods
to match Associated Press style.) to match Associated Press style.)
A ``'AM'`` or ``'PM'``. ``'AM'`` A ``'AM'`` or ``'PM'``. ``'AM'``
b Month, textual, 3 letters, lowercase. ``'jan'``
B Not implemented. B Not implemented.
d Day of the month, 2 digits with ``'01'`` to ``'31'`` d Day of the month, 2 digits with ``'01'`` to ``'31'``
leading zeros. leading zeros.

View File

@ -17,6 +17,8 @@ r"""
'07' '07'
>>> format(my_birthday, 'M') >>> format(my_birthday, 'M')
'Jul' 'Jul'
>>> format(my_birthday, 'b')
'jul'
>>> format(my_birthday, 'n') >>> format(my_birthday, 'n')
'7' '7'
>>> format(my_birthday, 'N') >>> format(my_birthday, 'N')