1 \section{\module{calendar
} ---
2 General calendar-related functions
}
4 \declaremodule{standard
}{calendar
}
5 \modulesynopsis{General functions for working with the calendar,
6 including some emulation of the
\UNIX\
\program{cal
}
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.
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:
26 calendar.setfirstweekday(calendar.SUNDAY)
30 \begin{funcdesc
}{firstweekday
}{}
31 Returns the current setting for the weekday to start each week.
34 \begin{funcdesc
}{isleap
}{year
}
35 Returns true if
\var{year
} is a leap year.
38 \begin{funcdesc
}{leapdays
}{y1, y2
}
39 Returns the number of leap years in the range
40 [\var{y1
}\ldots\var{y2
}).
43 \begin{funcdesc
}{weekday
}{year, month, day
}
44 Returns the day of the week (
\code{0} is Monday) for
\var{year
}
45 (
\code{1970}--
\ldots),
\var{month
} (
\code{1}--
\code{12}),
\var{day
}
46 (
\code{1}--
\code{31}).
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
}.
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.
57 Each week begins with Monday unless set by
\function{setfirstweekday()
}.
60 \begin{funcdesc
}{prmonth
}{theyear, themonth
\optional{, w
\optional{, l
}}}
61 Prints a month's calendar as returned by
\function{month()
}.
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()
}.
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()
}.
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
82 \function{setfirstweekday()
}.
85 \begin{funcdesc
}{timegm
}{tuple
}
86 An unrelated but handy function that takes a time tuple such as
87 returned by the
\function{gmtime()
} function in the
\refmodule{time
}
88 module, and returns the corresponding Unix timestamp value, assuming
89 an epoch of
1970, and the POSIX encoding. In fact,
90 \function{time.gmtime()
} and
\function{timegm()
} are each others' inverse.
95 \seemodule{time
}{Low-level time related functions.
}