Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / lib / module-calendar.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-cmd.html" />
<link rel="prev" href="module-fileinput.html" />
<link rel="parent" href="misc.html" />
<link rel="next" href="module-cmd.html" />
<meta name='aesop' content='information' />
<title>5.19 calendar -- General calendar-related functions</title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="5.18 fileinput "
href="module-fileinput.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="5. Miscellaneous Services"
href="misc.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="5.20 cmd "
href="module-cmd.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-fileinput.html">5.18 fileinput </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="misc.html">5. Miscellaneous Services</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-cmd.html">5.20 cmd </A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0071900000000000000000">
5.19 <tt class="module">calendar</tt> --
General calendar-related functions</A>
</H1>
<P>
<A NAME="module-calendar"></A>
<P>
This module allows you to output calendars like the <span class="Unix">Unix</span>
<b class="program">cal</b> program, and provides additional useful functions
related to the calendar. By default, these calendars have Monday as
the first day of the week, and Sunday as the last (the European
convention). Use <tt class="function">setfirstweekday()</tt> to set the first day of the
week to Sunday (6) or to any other weekday. Parameters that specify
dates are given as integers.
<P>
Most of these functions rely on the <tt class="module">datetime</tt> module which
uses an idealized calendar, the current Gregorian calendar indefinitely
extended in both directions. This matches the definition of the
"proleptic Gregorian" calendar in Dershowitz and Reingold's book
"Calendrical Calculations", where it's the base calendar for all
computations.
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1446' xml:id='l2h-1446' class="function">setfirstweekday</tt></b>(</nobr></td>
<td><var>weekday</var>)</td></tr></table></dt>
<dd>
Sets the weekday (<code>0</code> is Monday, <code>6</code> is Sunday) to start
each week. The values <tt class="constant">MONDAY</tt>, <tt class="constant">TUESDAY</tt>,
<tt class="constant">WEDNESDAY</tt>, <tt class="constant">THURSDAY</tt>, <tt class="constant">FRIDAY</tt>,
<tt class="constant">SATURDAY</tt>, and <tt class="constant">SUNDAY</tt> are provided for
convenience. For example, to set the first weekday to Sunday:
<P>
<div class="verbatim"><pre>
import calendar
calendar.setfirstweekday(calendar.SUNDAY)
</pre></div>
<span class="versionnote">New in version 2.0.</span>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1447' xml:id='l2h-1447' class="function">firstweekday</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Returns the current setting for the weekday to start each week.
<span class="versionnote">New in version 2.0.</span>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1448' xml:id='l2h-1448' class="function">isleap</tt></b>(</nobr></td>
<td><var>year</var>)</td></tr></table></dt>
<dd>
Returns <tt class="constant">True</tt> if <var>year</var> is a leap year, otherwise
<tt class="constant">False</tt>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1449' xml:id='l2h-1449' class="function">leapdays</tt></b>(</nobr></td>
<td><var>y1, y2</var>)</td></tr></table></dt>
<dd>
Returns the number of leap years in the range
[<var>y1</var>...<var>y2</var>), where <var>y1</var> and <var>y2</var> are years.
<span class="versionnote">Changed in version 2.0:
This function didn't work for ranges spanning
a century change in Python 1.5.2.</span>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1450' xml:id='l2h-1450' class="function">weekday</tt></b>(</nobr></td>
<td><var>year, month, day</var>)</td></tr></table></dt>
<dd>
Returns the day of the week (<code>0</code> is Monday) for <var>year</var>
(<code>1970</code>-...), <var>month</var> (<code>1</code>-<code>12</code>), <var>day</var>
(<code>1</code>-<code>31</code>).
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1451' xml:id='l2h-1451' class="function">weekheader</tt></b>(</nobr></td>
<td><var>n</var>)</td></tr></table></dt>
<dd>
Return a header containing abbreviated weekday names. <var>n</var> specifies
the width in characters for one weekday.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1452' xml:id='l2h-1452' class="function">monthrange</tt></b>(</nobr></td>
<td><var>year, month</var>)</td></tr></table></dt>
<dd>
Returns weekday of first day of the month and number of days in month,
for the specified <var>year</var> and <var>month</var>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1453' xml:id='l2h-1453' class="function">monthcalendar</tt></b>(</nobr></td>
<td><var>year, month</var>)</td></tr></table></dt>
<dd>
Returns a matrix representing a month's calendar. Each row represents
a week; days outside of the month a represented by zeros.
Each week begins with Monday unless set by <tt class="function">setfirstweekday()</tt>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1454' xml:id='l2h-1454' class="function">prmonth</tt></b>(</nobr></td>
<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>
<dd>
Prints a month's calendar as returned by <tt class="function">month()</tt>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1455' xml:id='l2h-1455' class="function">month</tt></b>(</nobr></td>
<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>
<dd>
Returns a month's calendar in a multi-line string. If <var>w</var> is
provided, it specifies the width of the date columns, which are
centered. If <var>l</var> is given, it specifies the number of lines that
each week will use. Depends on the first weekday as set by
<tt class="function">setfirstweekday()</tt>.
<span class="versionnote">New in version 2.0.</span>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1456' xml:id='l2h-1456' class="function">prcal</tt></b>(</nobr></td>
<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>
<dd>
Prints the calendar for an entire year as returned by
<tt class="function">calendar()</tt>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1457' xml:id='l2h-1457' class="function">calendar</tt></b>(</nobr></td>
<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>
<dd>
Returns a 3-column calendar for an entire year as a multi-line string.
Optional parameters <var>w</var>, <var>l</var>, and <var>c</var> are for date column
width, lines per week, and number of spaces between month columns,
respectively. Depends on the first weekday as set by
<tt class="function">setfirstweekday()</tt>. The earliest year for which a calendar can
be generated is platform-dependent.
<span class="versionnote">New in version 2.0.</span>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-1458' xml:id='l2h-1458' class="function">timegm</tt></b>(</nobr></td>
<td><var>tuple</var>)</td></tr></table></dt>
<dd>
An unrelated but handy function that takes a time tuple such as
returned by the <tt class="function">gmtime()</tt> function in the <tt class="module"><a href="module-time.html">time</a></tt>
module, and returns the corresponding <span class="Unix">Unix</span> timestamp value, assuming
an epoch of 1970, and the POSIX encoding. In fact,
<tt class="function">time.gmtime()</tt> and <tt class="function">timegm()</tt> are each others' inverse.
<span class="versionnote">New in version 2.0.</span>
</dl>
<P>
<div class="seealso">
<p class="heading">See Also:</p>
<dl compact="compact" class="seemodule">
<dt>Module <b><tt class="module"><a href="module-datetime.html">datetime</a></tt>:</b>
<dd>Object-oriented interface to dates and times
with similar functionality to the
<tt class="module"><a href="module-time.html">time</a></tt> module.
</dl>
<dl compact="compact" class="seemodule">
<dt>Module <b><tt class="module"><a href="module-time.html">time</a></tt>:</b>
<dd>Low-level time related functions.
</dl>
</div>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="5.18 fileinput "
href="module-fileinput.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="5. Miscellaneous Services"
href="misc.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="5.20 cmd "
href="module-cmd.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-fileinput.html">5.18 fileinput </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="misc.html">5. Miscellaneous Services</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-cmd.html">5.20 cmd </A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>