| first day of the week. ``0`` is Monday (the default), ``6`` is Sunday. |
| |
| A :class:`Calendar` object provides several methods that can be used for |
| preparing the calendar data for formatting. This class doesn't do any formatting |
| itself. This is the job of subclasses. |
| |
| .. versionadded:: 2.5 |
| |
n | :class:`Calendar` instances have the following methods: |
n | :class:`Calendar` instances have the following methods: |
| |
| |
n | .. method:: Calendar.iterweekdays(weekday) |
n | .. method:: iterweekdays() |
| |
n | Return an iterator for the week day numbers that will be used for one week. The |
n | Return an iterator for the week day numbers that will be used for one |
| first number from the iterator will be the same as the number returned by |
| week. The first value from the iterator will be the same as the value of |
| :meth:`firstweekday`. |
| the :attr:`firstweekday` property. |
| |
| |
n | .. method:: Calendar.itermonthdates(year, month) |
n | .. method:: itermonthdates(year, month) |
| |
n | Return an iterator for the month *month* (1-12) in the year *year*. This |
n | Return an iterator for the month *month* (1-12) in the year *year*. This |
| iterator will return all days (as :class:`datetime.date` objects) for the month |
| iterator will return all days (as :class:`datetime.date` objects) for the |
| and all days before the start of the month or after the end of the month that |
| month and all days before the start of the month or after the end of the |
| are required to get a complete week. |
| month that are required to get a complete week. |
| |
| |
n | .. method:: Calendar.itermonthdays2(year, month) |
n | .. method:: itermonthdays2(year, month) |
| |
n | Return an iterator for the month *month* in the year *year* similar to |
n | Return an iterator for the month *month* in the year *year* similar to |
| :meth:`itermonthdates`. Days returned will be tuples consisting of a day number |
| :meth:`itermonthdates`. Days returned will be tuples consisting of a day |
| and a week day number. |
| number and a week day number. |
| |
| |
n | .. method:: Calendar.itermonthdays(year, month) |
n | .. method:: itermonthdays(year, month) |
| |
n | Return an iterator for the month *month* in the year *year* similar to |
n | Return an iterator for the month *month* in the year *year* similar to |
| :meth:`itermonthdates`. Days returned will simply be day numbers. |
| :meth:`itermonthdates`. Days returned will simply be day numbers. |
| |
| |
n | .. method:: Calendar.monthdatescalendar(year, month) |
n | .. method:: monthdatescalendar(year, month) |
| |
n | Return a list of the weeks in the month *month* of the *year* as full weeks. |
n | Return a list of the weeks in the month *month* of the *year* as full |
| Weeks are lists of seven :class:`datetime.date` objects. |
| weeks. Weeks are lists of seven :class:`datetime.date` objects. |
| |
| |
n | .. method:: Calendar.monthdays2calendar(year, month) |
n | .. method:: monthdays2calendar(year, month) |
| |
n | Return a list of the weeks in the month *month* of the *year* as full weeks. |
n | Return a list of the weeks in the month *month* of the *year* as full |
| Weeks are lists of seven tuples of day numbers and weekday numbers. |
| weeks. Weeks are lists of seven tuples of day numbers and weekday |
| numbers. |
| |
| |
n | .. method:: Calendar.monthdayscalendar(year, month) |
n | .. method:: monthdayscalendar(year, month) |
| |
n | Return a list of the weeks in the month *month* of the *year* as full weeks. |
n | Return a list of the weeks in the month *month* of the *year* as full |
| Weeks are lists of seven day numbers. |
| weeks. Weeks are lists of seven day numbers. |
| |
| |
n | .. method:: Calendar.yeardatescalendar(year, month[, width]) |
n | .. method:: yeardatescalendar(year[, width]) |
| |
n | Return the data for the specified year ready for formatting. The return value is |
n | Return the data for the specified year ready for formatting. The return |
| a list of month rows. Each month row contains up to *width* months (defaulting |
| value is a list of month rows. Each month row contains up to *width* |
| to 3). Each month contains between 4 and 6 weeks and each week contains 1--7 |
| months (defaulting to 3). Each month contains between 4 and 6 weeks and |
| days. Days are :class:`datetime.date` objects. |
| each week contains 1--7 days. Days are :class:`datetime.date` objects. |
| |
| |
n | .. method:: Calendar.yeardays2calendar(year, month[, width]) |
n | .. method:: yeardays2calendar(year[, width]) |
| |
n | Return the data for the specified year ready for formatting (similar to |
n | Return the data for the specified year ready for formatting (similar to |
| :meth:`yeardatescalendar`). Entries in the week lists are tuples of day numbers |
| :meth:`yeardatescalendar`). Entries in the week lists are tuples of day |
| and weekday numbers. Day numbers outside this month are zero. |
| numbers and weekday numbers. Day numbers outside this month are zero. |
| |
| |
n | .. method:: Calendar.yeardayscalendar(year, month[, width]) |
n | .. method:: yeardayscalendar(year[, width]) |
| |
n | Return the data for the specified year ready for formatting (similar to |
n | Return the data for the specified year ready for formatting (similar to |
| :meth:`yeardatescalendar`). Entries in the week lists are day numbers. Day |
| :meth:`yeardatescalendar`). Entries in the week lists are day numbers. Day |
| numbers outside this month are zero. |
| numbers outside this month are zero. |
| |
| |
| .. class:: TextCalendar([firstweekday]) |
| |
| This class can be used to generate plain text calendars. |
| |
| .. versionadded:: 2.5 |
| |
n | :class:`TextCalendar` instances have the following methods: |
n | :class:`TextCalendar` instances have the following methods: |
| |
| |
n | .. method:: TextCalendar.formatmonth(theyear, themonth[, w[, l]]) |
n | .. method:: formatmonth(theyear, themonth[, w[, l]]) |
| |
n | Return a month's calendar in a multi-line string. If *w* is provided, it |
n | Return a month's calendar in a multi-line string. If *w* is provided, it |
| specifies the width of the date columns, which are centered. If *l* is given, it |
| specifies the width of the date columns, which are centered. If *l* is |
| specifies the number of lines that each week will use. Depends on the first |
| given, it specifies the number of lines that each week will use. Depends |
| weekday as set by :func:`setfirstweekday`. |
| on the first weekday as specified in the constructor or set by the |
| :meth:`setfirstweekday` method. |
| |
| |
n | .. method:: TextCalendar.prmonth(theyear, themonth[, w[, l]]) |
n | .. method:: prmonth(theyear, themonth[, w[, l]]) |
| |
n | Print a month's calendar as returned by :meth:`formatmonth`. |
n | Print a month's calendar as returned by :meth:`formatmonth`. |
| |
| |
n | .. method:: TextCalendar.formatyear(theyear, themonth[, w[, l[, c[, m]]]]) |
n | .. method:: formatyear(theyear, themonth[, w[, l[, c[, m]]]]) |
| |
n | Return a *m*-column calendar for an entire year as a multi-line string. Optional |
n | Return a *m*-column calendar for an entire year as a multi-line string. |
| parameters *w*, *l*, and *c* are for date column width, lines per week, and |
| Optional parameters *w*, *l*, and *c* are for date column width, lines per |
| number of spaces between month columns, respectively. Depends on the first |
| week, and number of spaces between month columns, respectively. Depends on |
| the first weekday as specified in the constructor or set by the |
| weekday as set by :meth:`setfirstweekday`. The earliest year for which a |
| :meth:`setfirstweekday` method. The earliest year for which a calendar |
| calendar can be generated is platform-dependent. |
| can be generated is platform-dependent. |
| |
| |
n | .. method:: TextCalendar.pryear(theyear[, w[, l[, c[, m]]]]) |
n | .. method:: pryear(theyear[, w[, l[, c[, m]]]]) |
| |
n | Print the calendar for an entire year as returned by :meth:`formatyear`. |
n | Print the calendar for an entire year as returned by :meth:`formatyear`. |
| |
| |
| .. class:: HTMLCalendar([firstweekday]) |
| |
| This class can be used to generate HTML calendars. |
| |
| .. versionadded:: 2.5 |
| |
n | :class:`HTMLCalendar` instances have the following methods: |
n | :class:`HTMLCalendar` instances have the following methods: |
| |
| |
n | .. method:: HTMLCalendar.formatmonth(theyear, themonth[, withyear]) |
n | .. method:: formatmonth(theyear, themonth[, withyear]) |
| |
n | Return a month's calendar as an HTML table. If *withyear* is true the year will |
n | Return a month's calendar as an HTML table. If *withyear* is true the year |
| be included in the header, otherwise just the month name will be used. |
| will be included in the header, otherwise just the month name will be |
| used. |
| |
| |
n | .. method:: HTMLCalendar.formatyear(theyear, themonth[, width]) |
n | .. method:: formatyear(theyear, themonth[, width]) |
| |
n | Return a year's calendar as an HTML table. *width* (defaulting to 3) specifies |
n | Return a year's calendar as an HTML table. *width* (defaulting to 3) |
| the number of months per row. |
| specifies the number of months per row. |
| |
| |
n | .. method:: HTMLCalendar.formatyearpage(theyear, themonth[, width[, css[, encoding]]]) |
n | .. method:: formatyearpage(theyear[, width[, css[, encoding]]]) |
| |
n | Return a year's calendar as a complete HTML page. *width* (defaulting to 3) |
n | Return a year's calendar as a complete HTML page. *width* (defaulting to |
| specifies the number of months per row. *css* is the name for the cascading |
| 3) specifies the number of months per row. *css* is the name for the |
| style sheet to be used. :const:`None` can be passed if no style sheet should be |
| cascading style sheet to be used. :const:`None` can be passed if no style |
| used. *encoding* specifies the encoding to be used for the output (defaulting to |
| sheet should be used. *encoding* specifies the encoding to be used for the |
| the system default encoding). |
| output (defaulting to the system default encoding). |
| |
| |
| .. class:: LocaleTextCalendar([firstweekday[, locale]]) |
| |
| This subclass of :class:`TextCalendar` can be passed a locale name in the |
n | constructor and will return month and weekday names in the specified locale. If |
n | constructor and will return month and weekday names in the specified |
| this locale includes an encoding all strings containing month and weekday names |
| locale. If this locale includes an encoding all strings containing month and |
| will be returned as unicode. |
| weekday names will be returned as unicode. |
| |
| .. versionadded:: 2.5 |
| |
| |
| .. class:: LocaleHTMLCalendar([firstweekday[, locale]]) |
| |
| This subclass of :class:`HTMLCalendar` can be passed a locale name in the |
n | constructor and will return month and weekday names in the specified locale. If |
n | constructor and will return month and weekday names in the specified |
| this locale includes an encoding all strings containing month and weekday names |
| locale. If this locale includes an encoding all strings containing month and |
| will be returned as unicode. |
| weekday names will be returned as unicode. |
| |
| .. versionadded:: 2.5 |
| |
| For simple text calendars this module provides the following functions. |
| |
| |
| .. function:: setfirstweekday(weekday) |
| |