Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-cmd.html" /> | |
13 | <link rel="prev" href="module-fileinput.html" /> | |
14 | <link rel="parent" href="misc.html" /> | |
15 | <link rel="next" href="module-cmd.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>5.19 calendar -- General calendar-related functions</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="5.18 fileinput " | |
25 | href="module-fileinput.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="5. Miscellaneous Services" | |
28 | href="misc.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="5.20 cmd " | |
31 | href="module-cmd.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-fileinput.html">5.18 fileinput </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="misc.html">5. Miscellaneous Services</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-cmd.html">5.20 cmd </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION0071900000000000000000"> | |
56 | 5.19 <tt class="module">calendar</tt> -- | |
57 | General calendar-related functions</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-calendar"></A> | |
62 | ||
63 | <P> | |
64 | This module allows you to output calendars like the <span class="Unix">Unix</span> | |
65 | <b class="program">cal</b> program, and provides additional useful functions | |
66 | related to the calendar. By default, these calendars have Monday as | |
67 | the first day of the week, and Sunday as the last (the European | |
68 | convention). Use <tt class="function">setfirstweekday()</tt> to set the first day of the | |
69 | week to Sunday (6) or to any other weekday. Parameters that specify | |
70 | dates are given as integers. | |
71 | ||
72 | <P> | |
73 | Most of these functions rely on the <tt class="module">datetime</tt> module which | |
74 | uses an idealized calendar, the current Gregorian calendar indefinitely | |
75 | extended in both directions. This matches the definition of the | |
76 | "proleptic Gregorian" calendar in Dershowitz and Reingold's book | |
77 | "Calendrical Calculations", where it's the base calendar for all | |
78 | computations. | |
79 | ||
80 | <P> | |
81 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
82 | <td><nobr><b><tt id='l2h-1446' xml:id='l2h-1446' class="function">setfirstweekday</tt></b>(</nobr></td> | |
83 | <td><var>weekday</var>)</td></tr></table></dt> | |
84 | <dd> | |
85 | Sets the weekday (<code>0</code> is Monday, <code>6</code> is Sunday) to start | |
86 | each week. The values <tt class="constant">MONDAY</tt>, <tt class="constant">TUESDAY</tt>, | |
87 | <tt class="constant">WEDNESDAY</tt>, <tt class="constant">THURSDAY</tt>, <tt class="constant">FRIDAY</tt>, | |
88 | <tt class="constant">SATURDAY</tt>, and <tt class="constant">SUNDAY</tt> are provided for | |
89 | convenience. For example, to set the first weekday to Sunday: | |
90 | ||
91 | <P> | |
92 | <div class="verbatim"><pre> | |
93 | import calendar | |
94 | calendar.setfirstweekday(calendar.SUNDAY) | |
95 | </pre></div> | |
96 | ||
97 | <span class="versionnote">New in version 2.0.</span> | |
98 | ||
99 | </dl> | |
100 | ||
101 | <P> | |
102 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
103 | <td><nobr><b><tt id='l2h-1447' xml:id='l2h-1447' class="function">firstweekday</tt></b>(</nobr></td> | |
104 | <td><var></var>)</td></tr></table></dt> | |
105 | <dd> | |
106 | Returns the current setting for the weekday to start each week. | |
107 | ||
108 | <span class="versionnote">New in version 2.0.</span> | |
109 | ||
110 | </dl> | |
111 | ||
112 | <P> | |
113 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
114 | <td><nobr><b><tt id='l2h-1448' xml:id='l2h-1448' class="function">isleap</tt></b>(</nobr></td> | |
115 | <td><var>year</var>)</td></tr></table></dt> | |
116 | <dd> | |
117 | Returns <tt class="constant">True</tt> if <var>year</var> is a leap year, otherwise | |
118 | <tt class="constant">False</tt>. | |
119 | </dl> | |
120 | ||
121 | <P> | |
122 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
123 | <td><nobr><b><tt id='l2h-1449' xml:id='l2h-1449' class="function">leapdays</tt></b>(</nobr></td> | |
124 | <td><var>y1, y2</var>)</td></tr></table></dt> | |
125 | <dd> | |
126 | Returns the number of leap years in the range | |
127 | [<var>y1</var>...<var>y2</var>), where <var>y1</var> and <var>y2</var> are years. | |
128 | ||
129 | <span class="versionnote">Changed in version 2.0: | |
130 | This function didn't work for ranges spanning | |
131 | a century change in Python 1.5.2.</span> | |
132 | ||
133 | </dl> | |
134 | ||
135 | <P> | |
136 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
137 | <td><nobr><b><tt id='l2h-1450' xml:id='l2h-1450' class="function">weekday</tt></b>(</nobr></td> | |
138 | <td><var>year, month, day</var>)</td></tr></table></dt> | |
139 | <dd> | |
140 | Returns the day of the week (<code>0</code> is Monday) for <var>year</var> | |
141 | (<code>1970</code>-...), <var>month</var> (<code>1</code>-<code>12</code>), <var>day</var> | |
142 | (<code>1</code>-<code>31</code>). | |
143 | </dl> | |
144 | ||
145 | <P> | |
146 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
147 | <td><nobr><b><tt id='l2h-1451' xml:id='l2h-1451' class="function">weekheader</tt></b>(</nobr></td> | |
148 | <td><var>n</var>)</td></tr></table></dt> | |
149 | <dd> | |
150 | Return a header containing abbreviated weekday names. <var>n</var> specifies | |
151 | the width in characters for one weekday. | |
152 | </dl> | |
153 | ||
154 | <P> | |
155 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
156 | <td><nobr><b><tt id='l2h-1452' xml:id='l2h-1452' class="function">monthrange</tt></b>(</nobr></td> | |
157 | <td><var>year, month</var>)</td></tr></table></dt> | |
158 | <dd> | |
159 | Returns weekday of first day of the month and number of days in month, | |
160 | for the specified <var>year</var> and <var>month</var>. | |
161 | </dl> | |
162 | ||
163 | <P> | |
164 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
165 | <td><nobr><b><tt id='l2h-1453' xml:id='l2h-1453' class="function">monthcalendar</tt></b>(</nobr></td> | |
166 | <td><var>year, month</var>)</td></tr></table></dt> | |
167 | <dd> | |
168 | Returns a matrix representing a month's calendar. Each row represents | |
169 | a week; days outside of the month a represented by zeros. | |
170 | Each week begins with Monday unless set by <tt class="function">setfirstweekday()</tt>. | |
171 | </dl> | |
172 | ||
173 | <P> | |
174 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
175 | <td><nobr><b><tt id='l2h-1454' xml:id='l2h-1454' class="function">prmonth</tt></b>(</nobr></td> | |
176 | <td><var>theyear, themonth</var><big>[</big><var>, w</var><big>[</big><var>, l</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
177 | <dd> | |
178 | Prints a month's calendar as returned by <tt class="function">month()</tt>. | |
179 | </dl> | |
180 | ||
181 | <P> | |
182 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
183 | <td><nobr><b><tt id='l2h-1455' xml:id='l2h-1455' class="function">month</tt></b>(</nobr></td> | |
184 | <td><var>theyear, themonth</var><big>[</big><var>, w</var><big>[</big><var>, l</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
185 | <dd> | |
186 | Returns a month's calendar in a multi-line string. If <var>w</var> is | |
187 | provided, it specifies the width of the date columns, which are | |
188 | centered. If <var>l</var> is given, it specifies the number of lines that | |
189 | each week will use. Depends on the first weekday as set by | |
190 | <tt class="function">setfirstweekday()</tt>. | |
191 | ||
192 | <span class="versionnote">New in version 2.0.</span> | |
193 | ||
194 | </dl> | |
195 | ||
196 | <P> | |
197 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
198 | <td><nobr><b><tt id='l2h-1456' xml:id='l2h-1456' class="function">prcal</tt></b>(</nobr></td> | |
199 | <td><var>year</var><big>[</big><var>, w</var><big>[</big><var>, l</var><big>[</big><var>c</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
200 | <dd> | |
201 | Prints the calendar for an entire year as returned by | |
202 | <tt class="function">calendar()</tt>. | |
203 | </dl> | |
204 | ||
205 | <P> | |
206 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
207 | <td><nobr><b><tt id='l2h-1457' xml:id='l2h-1457' class="function">calendar</tt></b>(</nobr></td> | |
208 | <td><var>year</var><big>[</big><var>, w</var><big>[</big><var>, l</var><big>[</big><var>c</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
209 | <dd> | |
210 | Returns a 3-column calendar for an entire year as a multi-line string. | |
211 | Optional parameters <var>w</var>, <var>l</var>, and <var>c</var> are for date column | |
212 | width, lines per week, and number of spaces between month columns, | |
213 | respectively. Depends on the first weekday as set by | |
214 | <tt class="function">setfirstweekday()</tt>. The earliest year for which a calendar can | |
215 | be generated is platform-dependent. | |
216 | ||
217 | <span class="versionnote">New in version 2.0.</span> | |
218 | ||
219 | </dl> | |
220 | ||
221 | <P> | |
222 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
223 | <td><nobr><b><tt id='l2h-1458' xml:id='l2h-1458' class="function">timegm</tt></b>(</nobr></td> | |
224 | <td><var>tuple</var>)</td></tr></table></dt> | |
225 | <dd> | |
226 | An unrelated but handy function that takes a time tuple such as | |
227 | returned by the <tt class="function">gmtime()</tt> function in the <tt class="module"><a href="module-time.html">time</a></tt> | |
228 | module, and returns the corresponding <span class="Unix">Unix</span> timestamp value, assuming | |
229 | an epoch of 1970, and the POSIX encoding. In fact, | |
230 | <tt class="function">time.gmtime()</tt> and <tt class="function">timegm()</tt> are each others' inverse. | |
231 | ||
232 | <span class="versionnote">New in version 2.0.</span> | |
233 | ||
234 | </dl> | |
235 | ||
236 | <P> | |
237 | <div class="seealso"> | |
238 | <p class="heading">See Also:</p> | |
239 | ||
240 | <dl compact="compact" class="seemodule"> | |
241 | <dt>Module <b><tt class="module"><a href="module-datetime.html">datetime</a></tt>:</b> | |
242 | <dd>Object-oriented interface to dates and times | |
243 | with similar functionality to the | |
244 | <tt class="module"><a href="module-time.html">time</a></tt> module. | |
245 | </dl> | |
246 | <dl compact="compact" class="seemodule"> | |
247 | <dt>Module <b><tt class="module"><a href="module-time.html">time</a></tt>:</b> | |
248 | <dd>Low-level time related functions. | |
249 | </dl> | |
250 | </div> | |
251 | ||
252 | <DIV CLASS="navigation"> | |
253 | <div class='online-navigation'> | |
254 | <p></p><hr /> | |
255 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
256 | <tr> | |
257 | <td class='online-navigation'><a rel="prev" title="5.18 fileinput " | |
258 | href="module-fileinput.html"><img src='../icons/previous.png' | |
259 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
260 | <td class='online-navigation'><a rel="parent" title="5. Miscellaneous Services" | |
261 | href="misc.html"><img src='../icons/up.png' | |
262 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
263 | <td class='online-navigation'><a rel="next" title="5.20 cmd " | |
264 | href="module-cmd.html"><img src='../icons/next.png' | |
265 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
266 | <td align="center" width="100%">Python Library Reference</td> | |
267 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
268 | href="contents.html"><img src='../icons/contents.png' | |
269 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
270 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
271 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
272 | <td class='online-navigation'><a rel="index" title="Index" | |
273 | href="genindex.html"><img src='../icons/index.png' | |
274 | border='0' height='32' alt='Index' width='32' /></A></td> | |
275 | </tr></table> | |
276 | <div class='online-navigation'> | |
277 | <b class="navlabel">Previous:</b> | |
278 | <a class="sectref" rel="prev" href="module-fileinput.html">5.18 fileinput </A> | |
279 | <b class="navlabel">Up:</b> | |
280 | <a class="sectref" rel="parent" href="misc.html">5. Miscellaneous Services</A> | |
281 | <b class="navlabel">Next:</b> | |
282 | <a class="sectref" rel="next" href="module-cmd.html">5.20 cmd </A> | |
283 | </div> | |
284 | </div> | |
285 | <hr /> | |
286 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
287 | </DIV> | |
288 | <!--End of Navigation Panel--> | |
289 | <ADDRESS> | |
290 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
291 | </ADDRESS> | |
292 | </BODY> | |
293 | </HTML> |