Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{calendar} --- |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 2 | General calendar-related functions} |
| 3 | |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 4 | \declaremodule{standard}{calendar} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 5 | \modulesynopsis{General functions for working with the calendar, |
Fred Drake | c116b82 | 2001-05-09 15:50:17 +0000 | [diff] [blame] | 6 | including some emulation of the \UNIX\ \program{cal} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 7 | program.} |
| 8 | \sectionauthor{Drew Csillag}{drew_csillag@geocities.com} |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 9 | |
| 10 | This module allows you to output calendars like the \UNIX{} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 11 | \program{cal} program, and provides additional useful functions |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 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. |
| 16 | |
| 17 | \begin{funcdesc}{setfirstweekday}{weekday} |
| 18 | Sets the weekday (\code{0} is Monday, \code{6} is Sunday) to start |
| 19 | each week. The values \constant{MONDAY}, \constant{TUESDAY}, |
| 20 | \constant{WEDNESDAY}, \constant{THURSDAY}, \constant{FRIDAY}, |
| 21 | \constant{SATURDAY}, and \constant{SUNDAY} are provided for |
| 22 | convenience. For example, to set the first weekday to Sunday: |
| 23 | |
| 24 | \begin{verbatim} |
| 25 | import calendar |
| 26 | calendar.setfirstweekday(calendar.SUNDAY) |
| 27 | \end{verbatim} |
| 28 | \end{funcdesc} |
| 29 | |
| 30 | \begin{funcdesc}{firstweekday}{} |
| 31 | Returns the current setting for the weekday to start each week. |
| 32 | \end{funcdesc} |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 33 | |
| 34 | \begin{funcdesc}{isleap}{year} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 35 | Returns true if \var{year} is a leap year. |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 36 | \end{funcdesc} |
| 37 | |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 38 | \begin{funcdesc}{leapdays}{y1, y2} |
| 39 | Returns the number of leap years in the range |
Fred Drake | 3383792 | 2000-10-09 15:27:31 +0000 | [diff] [blame] | 40 | [\var{y1}\ldots\var{y2}). |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 41 | \end{funcdesc} |
| 42 | |
| 43 | \begin{funcdesc}{weekday}{year, month, day} |
| 44 | Returns the day of the week (\code{0} is Monday) for \var{year} |
Fred Drake | 02379fa | 1998-05-08 15:39:40 +0000 | [diff] [blame] | 45 | (\code{1970}--\ldots), \var{month} (\code{1}--\code{12}), \var{day} |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 46 | (\code{1}--\code{31}). |
| 47 | \end{funcdesc} |
| 48 | |
| 49 | \begin{funcdesc}{monthrange}{year, month} |
| 50 | Returns weekday of first day of the month and number of days in month, |
| 51 | for the specified \var{year} and \var{month}. |
| 52 | \end{funcdesc} |
| 53 | |
| 54 | \begin{funcdesc}{monthcalendar}{year, month} |
| 55 | Returns a matrix representing a month's calendar. Each row represents |
| 56 | a week; days outside of the month a represented by zeros. |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 57 | Each week begins with Monday unless set by \function{setfirstweekday()}. |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 58 | \end{funcdesc} |
| 59 | |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 60 | \begin{funcdesc}{prmonth}{theyear, themonth\optional{, w\optional{, l}}} |
| 61 | Prints a month's calendar as returned by \function{month()}. |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 62 | \end{funcdesc} |
| 63 | |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 64 | \begin{funcdesc}{month}{theyear, themonth\optional{, w\optional{, l}}} |
| 65 | Returns a month's calendar in a multi-line string. If \var{w} is |
| 66 | provided, it specifies the width of the date columns, which are |
| 67 | centered. If \var{l} is given, it specifies the number of lines that |
| 68 | each week will use. Depends on the first weekday as set by |
| 69 | \function{setfirstweekday()}. |
| 70 | \end{funcdesc} |
| 71 | |
| 72 | \begin{funcdesc}{prcal}{year\optional{, w\optional{, l\optional{c}}}} |
| 73 | Prints the calendar for an entire year as returned by |
| 74 | \function{calendar()}. |
| 75 | \end{funcdesc} |
| 76 | |
| 77 | \begin{funcdesc}{calendar}{year\optional{, w\optional{, l\optional{c}}}} |
| 78 | Returns a 3-column calendar for an entire year as a multi-line string. |
| 79 | Optional parameters \var{w}, \var{l}, and \var{c} are for date column |
| 80 | width, lines per week, and number of spaces between month columns, |
| 81 | respectively. Depends on the first weekday as set by |
Skip Montanaro | 5ff41d1 | 2001-08-22 12:43:38 +0000 | [diff] [blame] | 82 | \function{setfirstweekday()}. The earliest year for which a calendar can |
| 83 | be generated is platform-dependent. |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 84 | \end{funcdesc} |
Guido van Rossum | 4727456 | 1999-06-09 15:11:58 +0000 | [diff] [blame] | 85 | |
| 86 | \begin{funcdesc}{timegm}{tuple} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 87 | An unrelated but handy function that takes a time tuple such as |
| 88 | returned by the \function{gmtime()} function in the \refmodule{time} |
Guido van Rossum | 4727456 | 1999-06-09 15:11:58 +0000 | [diff] [blame] | 89 | module, and returns the corresponding Unix timestamp value, assuming |
| 90 | an epoch of 1970, and the POSIX encoding. In fact, |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 91 | \function{time.gmtime()} and \function{timegm()} are each others' inverse. |
Guido van Rossum | 4727456 | 1999-06-09 15:11:58 +0000 | [diff] [blame] | 92 | \end{funcdesc} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 93 | |
| 94 | |
| 95 | \begin{seealso} |
| 96 | \seemodule{time}{Low-level time related functions.} |
| 97 | \end{seealso} |