Skip to content

Commit bb73426

Browse files
gh-108202: Document calendar.TextCalendar formatting helpers (#127608)
Document the following TextCalendar methods: - formatday() - formatmonthname() - formatweekday() - formatweekheader()
1 parent 0706bab commit bb73426

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

Doc/library/calendar.rst

+26-1
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,32 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
138138

139139
:class:`TextCalendar` instances have the following methods:
140140

141+
142+
.. method:: formatday(theday, weekday, width)
143+
144+
Return a string representing a single day formatted with the given *width*.
145+
If *theday* is ``0``, return a string of spaces of
146+
the specified width, representing an empty day. The *weekday* parameter
147+
is unused.
148+
141149
.. method:: formatweek(theweek, w=0)
142150

143151
Return a single week in a string with no newline. If *w* is provided, it
144152
specifies the width of the date columns, which are centered. Depends
145153
on the first weekday as specified in the constructor or set by the
146154
:meth:`setfirstweekday` method.
147155

156+
.. method:: formatweekday(weekday, width)
157+
158+
Return a string representing the name of a single weekday formatted to
159+
the specified *width*. The *weekday* parameter is an integer representing
160+
the day of the week, where ``0`` is Monday and ``6`` is Sunday.
161+
162+
.. method:: formatweekheader(width)
163+
164+
Return a string containing the header row of weekday names, formatted
165+
with the given *width* for each column. The names depend on the locale
166+
settings and are padded to the specified width.
148167

149168
.. method:: formatmonth(theyear, themonth, w=0, l=0)
150169

@@ -154,6 +173,12 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
154173
on the first weekday as specified in the constructor or set by the
155174
:meth:`setfirstweekday` method.
156175

176+
.. method:: formatmonthname(theyear, themonth, width=0, withyear=True)
177+
178+
Return a string representing the month's name centered within the
179+
specified *width*. If *withyear* is ``True``, include the year in the
180+
output. The *theyear* and *themonth* parameters specify the year
181+
and month for the name to be formatted respectively.
157182

158183
.. method:: prmonth(theyear, themonth, w=0, l=0)
159184

@@ -445,7 +470,7 @@ The :mod:`calendar` module exports the following data attributes:
445470

446471
A sequence that represents the months of the year in the current locale. This
447472
follows normal convention of January being month number 1, so it has a length of
448-
13 and ``month_name[0]`` is the empty string.
473+
13 and ``month_name[0]`` is the empty string.
449474

450475
>>> import calendar
451476
>>> list(calendar.month_name)

0 commit comments

Comments
 (0)