| 
									
										
										
										
											1998-08-10 19:42:37 +00:00
										 |  |  | \section{\module{calendar} --- | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  |          General calendar-related functions} | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | \declaremodule{standard}{calendar} | 
					
						
							|  |  |  | \modulesynopsis{General functions for working with the calendar, | 
					
						
							| 
									
										
										
										
											2001-05-09 15:50:17 +00:00
										 |  |  |                 including some emulation of the \UNIX\ \program{cal} | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  |                 program.} | 
					
						
							|  |  |  | \sectionauthor{Drew Csillag}{drew_csillag@geocities.com} | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | This module allows you to output calendars like the \UNIX{} | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | \program{cal} program, and provides additional useful functions | 
					
						
							| 
									
										
										
										
											2000-08-30 14:02:25 +00:00
										 |  |  | 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 \function{setfirstweekday()} to set the first day of the | 
					
						
							|  |  |  | week to Sunday (6) or to any other weekday. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{setfirstweekday}{weekday} | 
					
						
							|  |  |  | Sets the weekday (\code{0} is Monday, \code{6} is Sunday) to start | 
					
						
							|  |  |  | each week. The values \constant{MONDAY}, \constant{TUESDAY}, | 
					
						
							|  |  |  | \constant{WEDNESDAY}, \constant{THURSDAY}, \constant{FRIDAY}, | 
					
						
							|  |  |  | \constant{SATURDAY}, and \constant{SUNDAY} are provided for | 
					
						
							|  |  |  | convenience. For example, to set the first weekday to Sunday: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{verbatim} | 
					
						
							|  |  |  | import calendar | 
					
						
							|  |  |  | calendar.setfirstweekday(calendar.SUNDAY) | 
					
						
							|  |  |  | \end{verbatim} | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{firstweekday}{} | 
					
						
							|  |  |  | Returns the current setting for the weekday to start each week. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{isleap}{year} | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | Returns true if \var{year} is a leap year. | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:57 +00:00
										 |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-30 14:02:25 +00:00
										 |  |  | \begin{funcdesc}{leapdays}{y1, y2} | 
					
						
							|  |  |  | Returns the number of leap years in the range | 
					
						
							| 
									
										
										
										
											2000-10-09 15:27:31 +00:00
										 |  |  | [\var{y1}\ldots\var{y2}). | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:57 +00:00
										 |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{weekday}{year, month, day} | 
					
						
							|  |  |  | Returns the day of the week (\code{0} is Monday) for \var{year} | 
					
						
							| 
									
										
										
										
											1998-05-08 15:39:40 +00:00
										 |  |  | (\code{1970}--\ldots), \var{month} (\code{1}--\code{12}), \var{day} | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:57 +00:00
										 |  |  | (\code{1}--\code{31}). | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{monthrange}{year, month} | 
					
						
							|  |  |  | Returns weekday of first day of the month and number of days in month,  | 
					
						
							|  |  |  | for the specified \var{year} and \var{month}. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{monthcalendar}{year, month} | 
					
						
							|  |  |  | Returns a matrix representing a month's calendar.  Each row represents | 
					
						
							|  |  |  | a week; days outside of the month a represented by zeros. | 
					
						
							| 
									
										
										
										
											2000-08-30 14:02:25 +00:00
										 |  |  | Each week begins with Monday unless set by \function{setfirstweekday()}. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{prmonth}{theyear, themonth\optional{, w\optional{, l}}} | 
					
						
							|  |  |  | Prints a month's calendar as returned by \function{month()}. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{month}{theyear, themonth\optional{, w\optional{, l}}} | 
					
						
							|  |  |  | Returns a month's calendar in a multi-line string. If \var{w} is | 
					
						
							|  |  |  | provided, it specifies the width of the date columns, which are | 
					
						
							|  |  |  | centered. If \var{l} is given, it specifies the number of lines that | 
					
						
							|  |  |  | each week will use. Depends on the first weekday as set by | 
					
						
							|  |  |  | \function{setfirstweekday()}. | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:57 +00:00
										 |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-30 14:02:25 +00:00
										 |  |  | \begin{funcdesc}{prcal}{year\optional{, w\optional{, l\optional{c}}}} | 
					
						
							|  |  |  | Prints the calendar for an entire year as returned by  | 
					
						
							|  |  |  | \function{calendar()}. | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:57 +00:00
										 |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-30 14:02:25 +00:00
										 |  |  | \begin{funcdesc}{calendar}{year\optional{, w\optional{, l\optional{c}}}} | 
					
						
							|  |  |  | Returns a 3-column calendar for an entire year as a multi-line string. | 
					
						
							|  |  |  | Optional parameters \var{w}, \var{l}, and \var{c} are for date column | 
					
						
							|  |  |  | width, lines per week, and number of spaces between month columns, | 
					
						
							|  |  |  | respectively. Depends on the first weekday as set by | 
					
						
							| 
									
										
										
										
											2001-08-22 12:43:38 +00:00
										 |  |  | \function{setfirstweekday()}.  The earliest year for which a calendar can | 
					
						
							|  |  |  | be generated is platform-dependent. | 
					
						
							| 
									
										
										
										
											1998-04-28 14:28:57 +00:00
										 |  |  | \end{funcdesc} | 
					
						
							| 
									
										
										
										
											1999-06-09 15:11:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{timegm}{tuple} | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | An unrelated but handy function that takes a time tuple such as | 
					
						
							|  |  |  | returned by the \function{gmtime()} function in the \refmodule{time} | 
					
						
							| 
									
										
										
										
											1999-06-09 15:11:58 +00:00
										 |  |  | module, and returns the corresponding Unix timestamp value, assuming | 
					
						
							|  |  |  | an epoch of 1970, and the POSIX encoding.  In fact, | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | \function{time.gmtime()} and \function{timegm()} are each others' inverse. | 
					
						
							| 
									
										
										
										
											1999-06-09 15:11:58 +00:00
										 |  |  | \end{funcdesc} | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{seealso} | 
					
						
							|  |  |  |   \seemodule{time}{Low-level time related functions.} | 
					
						
							|  |  |  | \end{seealso} |