This commit was manufactured by cvs2svn to create tag 'r234c1'.
[python/dscho.git] / Doc / lib / libcalendar.tex
blobbf0c85bc2cb63fd0de1e50b2c1cf9fa0cf17e87b
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 \code{1} if \var{year} is a leap year, otherwise \code{0}.
46 \end{funcdesc}
48 \begin{funcdesc}{leapdays}{y1, y2}
49 Returns the number of leap years in the range
50 [\var{y1}\ldots\var{y2}), where \var{y1} and \var{y2} are years.
51 \versionchanged[This function didn't work for ranges spanning
52 a century change in Python 1.5.2]{2.0}
53 \end{funcdesc}
55 \begin{funcdesc}{weekday}{year, month, day}
56 Returns the day of the week (\code{0} is Monday) for \var{year}
57 (\code{1970}--\ldots), \var{month} (\code{1}--\code{12}), \var{day}
58 (\code{1}--\code{31}).
59 \end{funcdesc}
61 \begin{funcdesc}{monthrange}{year, month}
62 Returns weekday of first day of the month and number of days in month,
63 for the specified \var{year} and \var{month}.
64 \end{funcdesc}
66 \begin{funcdesc}{monthcalendar}{year, month}
67 Returns a matrix representing a month's calendar. Each row represents
68 a week; days outside of the month a represented by zeros.
69 Each week begins with Monday unless set by \function{setfirstweekday()}.
70 \end{funcdesc}
72 \begin{funcdesc}{prmonth}{theyear, themonth\optional{, w\optional{, l}}}
73 Prints a month's calendar as returned by \function{month()}.
74 \end{funcdesc}
76 \begin{funcdesc}{month}{theyear, themonth\optional{, w\optional{, l}}}
77 Returns a month's calendar in a multi-line string. If \var{w} is
78 provided, it specifies the width of the date columns, which are
79 centered. If \var{l} is given, it specifies the number of lines that
80 each week will use. Depends on the first weekday as set by
81 \function{setfirstweekday()}.
82 \versionadded{2.0}
83 \end{funcdesc}
85 \begin{funcdesc}{prcal}{year\optional{, w\optional{, l\optional{c}}}}
86 Prints the calendar for an entire year as returned by
87 \function{calendar()}.
88 \end{funcdesc}
90 \begin{funcdesc}{calendar}{year\optional{, w\optional{, l\optional{c}}}}
91 Returns a 3-column calendar for an entire year as a multi-line string.
92 Optional parameters \var{w}, \var{l}, and \var{c} are for date column
93 width, lines per week, and number of spaces between month columns,
94 respectively. Depends on the first weekday as set by
95 \function{setfirstweekday()}. The earliest year for which a calendar can
96 be generated is platform-dependent.
97 \versionadded{2.0}
98 \end{funcdesc}
100 \begin{funcdesc}{timegm}{tuple}
101 An unrelated but handy function that takes a time tuple such as
102 returned by the \function{gmtime()} function in the \refmodule{time}
103 module, and returns the corresponding \UNIX{} timestamp value, assuming
104 an epoch of 1970, and the POSIX encoding. In fact,
105 \function{time.gmtime()} and \function{timegm()} are each others' inverse.
106 \versionadded{2.0}
107 \end{funcdesc}
110 \begin{seealso}
111 \seemodule{time}{Low-level time related functions.}
112 \end{seealso}