Added a test for the ability to specify a class attribute in Formatter configuration...
[python.git] / Doc / lib / libcalendar.tex
blobbf3a7d64b8be94be2b2f7a39e39752d976e18e0f
1 \section{\module{calendar} ---
2 General calendar-related functions}
4 \declaremodule{standard}{calendar}
5 \modulesynopsis{Functions for working with calendars,
6 including some emulation of the \UNIX\ \program{cal}
7 program.}
8 \sectionauthor{Drew Csillag}{drew_csillag@geocities.com}
10 This module allows you to output calendars like the \UNIX{}
11 \program{cal} program, and provides additional useful functions
12 related to the calendar. By default, these calendars have Monday as
13 the first day of the week, and Sunday as the last (the European
14 convention). Use \function{setfirstweekday()} to set the first day of the
15 week to Sunday (6) or to any other weekday. Parameters that specify
16 dates are given as integers.
18 Most of these functions rely on the \module{datetime} module which
19 uses an idealized calendar, the current Gregorian calendar indefinitely
20 extended in both directions. This matches the definition of the
21 "proleptic Gregorian" calendar in Dershowitz and Reingold's book
22 "Calendrical Calculations", where it's the base calendar for all
23 computations.
25 \begin{funcdesc}{setfirstweekday}{weekday}
26 Sets the weekday (\code{0} is Monday, \code{6} is Sunday) to start
27 each week. The values \constant{MONDAY}, \constant{TUESDAY},
28 \constant{WEDNESDAY}, \constant{THURSDAY}, \constant{FRIDAY},
29 \constant{SATURDAY}, and \constant{SUNDAY} are provided for
30 convenience. For example, to set the first weekday to Sunday:
32 \begin{verbatim}
33 import calendar
34 calendar.setfirstweekday(calendar.SUNDAY)
35 \end{verbatim}
36 \versionadded{2.0}
37 \end{funcdesc}
39 \begin{funcdesc}{firstweekday}{}
40 Returns the current setting for the weekday to start each week.
41 \versionadded{2.0}
42 \end{funcdesc}
44 \begin{funcdesc}{isleap}{year}
45 Returns \constant{True} if \var{year} is a leap year, otherwise
46 \constant{False}.
47 \end{funcdesc}
49 \begin{funcdesc}{leapdays}{y1, y2}
50 Returns the number of leap years in the range
51 [\var{y1}\ldots\var{y2}), where \var{y1} and \var{y2} are years.
52 \versionchanged[This function didn't work for ranges spanning
53 a century change in Python 1.5.2]{2.0}
54 \end{funcdesc}
56 \begin{funcdesc}{weekday}{year, month, day}
57 Returns the day of the week (\code{0} is Monday) for \var{year}
58 (\code{1970}--\ldots), \var{month} (\code{1}--\code{12}), \var{day}
59 (\code{1}--\code{31}).
60 \end{funcdesc}
62 \begin{funcdesc}{weekheader}{n}
63 Return a header containing abbreviated weekday names. \var{n} specifies
64 the width in characters for one weekday.
65 \end{funcdesc}
67 \begin{funcdesc}{monthrange}{year, month}
68 Returns weekday of first day of the month and number of days in month,
69 for the specified \var{year} and \var{month}.
70 \end{funcdesc}
72 \begin{funcdesc}{monthcalendar}{year, month}
73 Returns a matrix representing a month's calendar. Each row represents
74 a week; days outside of the month a represented by zeros.
75 Each week begins with Monday unless set by \function{setfirstweekday()}.
76 \end{funcdesc}
78 \begin{funcdesc}{prmonth}{theyear, themonth\optional{, w\optional{, l}}}
79 Prints a month's calendar as returned by \function{month()}.
80 \end{funcdesc}
82 \begin{funcdesc}{month}{theyear, themonth\optional{, w\optional{, l}}}
83 Returns a month's calendar in a multi-line string. If \var{w} is
84 provided, it specifies the width of the date columns, which are
85 centered. If \var{l} is given, it specifies the number of lines that
86 each week will use. Depends on the first weekday as set by
87 \function{setfirstweekday()}.
88 \versionadded{2.0}
89 \end{funcdesc}
91 \begin{funcdesc}{prcal}{year\optional{, w\optional{, l\optional{c}}}}
92 Prints the calendar for an entire year as returned by
93 \function{calendar()}.
94 \end{funcdesc}
96 \begin{funcdesc}{calendar}{year\optional{, w\optional{, l\optional{c}}}}
97 Returns a 3-column calendar for an entire year as a multi-line string.
98 Optional parameters \var{w}, \var{l}, and \var{c} are for date column
99 width, lines per week, and number of spaces between month columns,
100 respectively. Depends on the first weekday as set by
101 \function{setfirstweekday()}. The earliest year for which a calendar can
102 be generated is platform-dependent.
103 \versionadded{2.0}
104 \end{funcdesc}
106 \begin{funcdesc}{timegm}{tuple}
107 An unrelated but handy function that takes a time tuple such as
108 returned by the \function{gmtime()} function in the \refmodule{time}
109 module, and returns the corresponding \UNIX{} timestamp value, assuming
110 an epoch of 1970, and the POSIX encoding. In fact,
111 \function{time.gmtime()} and \function{timegm()} are each others' inverse.
112 \versionadded{2.0}
113 \end{funcdesc}
115 The \module{calendar} module exports the following data attributes:
117 \begin{datadesc}{day_name}
118 An array that represents the days of the week in the
119 current locale.
120 \end{datadesc}
122 \begin{datadesc}{day_abbr}
123 An array that represents the abbreviated days of the week
124 in the current locale.
125 \end{datadesc}
127 \begin{datadesc}{month_name}
128 An array that represents the months of the year in the
129 current locale. This follows normal convention
130 of January being month number 1, so it has a length of 13 and
131 \code{month_name[0]} is the empty string.
132 \end{datadesc}
134 \begin{datadesc}{month_abbr}
135 An array that represents the abbreviated months of the year
136 in the current locale. This follows normal convention
137 of January being month number 1, so it has a length of 13 and
138 \code{month_abbr[0]} is the empty string.
139 \end{datadesc}
141 \begin{seealso}
142 \seemodule{datetime}{Object-oriented interface to dates and times
143 with similar functionality to the
144 \refmodule{time} module.}
145 \seemodule{time}{Low-level time related functions.}
146 \end{seealso}