Skip to content

gh-108202: calendar: Document TextCalendar methods #127608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 3, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion Doc/library/calendar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,32 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is

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

.. method:: formatday(theday, weekday, width=2)

Return a string representing a single day formatted with the given width
which defaults to 2. If *theday* is ``0``, return a string of spaces of
the specified width, representing an empty day. The *weekday* parameter
represents the day of the week, where ``0`` is Monday and ``6`` is Sunday.

.. method:: formatweek(theweek, width=2)

Return a string representing an entire week formatted with the given width for each day.
The *theweek* parameter is a list of tuples, where each tuple contains a day of
the month or ``0`` for padding, and the corresponding weekday where 0 is
Monday and 6 is Sunday. Each day is padded to the specified width.

.. method:: formatweekday(weekday, width=2)

Return a string representing the name of a single weekday formatted to
the specified width. The *weekday* parameter is an integer representing
the day of the week, where 0 is Monday and 6 is Sunday.

.. method:: formatweekheader(width=2)

Return a string containing the header row of weekday names, formatted
with the given width for each column. The names depend on the locale
settings and are padded to the specified width.

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

Return a month's calendar in a multi-line string. If *w* is provided, it
Expand All @@ -146,12 +172,17 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
on the first weekday as specified in the constructor or set by the
:meth:`setfirstweekday` method.

.. method:: formatmonthname(theyear, themonth, width=0, withyear=True)

Return a string representing the month's name centered within the
specified width. If *withyear* is True, include the year in the
output. The *theyear* and *themonth* parameters specify the year
and month for the name to be formatted.

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

Print a month's calendar as returned by :meth:`formatmonth`.


.. method:: formatyear(theyear, w=2, l=1, c=6, m=3)

Return a *m*-column calendar for an entire year as a multi-line string.
Expand Down
Loading