General calendar-related functions
==================================
General functions for working with the calendar, including some
emulation of the UNIX `cal' program.
This manual section was written by Drew Csillag
<drew_csillag@geocities.com>.
This module allows you to output calendars like the UNIX `cal' 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 `setfirstweekday()'
to set the first day of the week to Sunday (6) or to any other weekday.
`setfirstweekday(weekday)'
Sets the weekday (`0' is Monday, `6' is Sunday) to start each
week. The values `MONDAY', `TUESDAY', `WEDNESDAY', `THURSDAY',
`FRIDAY', `SATURDAY', and `SUNDAY' are provided for convenience.
For example, to set the first weekday to Sunday:
import calendar
calendar.setfirstweekday(calendar.SUNDAY)
`firstweekday()'
Returns the current setting for the weekday to start each week.
`isleap(year)'
Returns true if YEAR is a leap year.
`leapdays(y1, y2)'
Returns the number of leap years in the range [Y1...Y2).
`weekday(year, month, day)'
Returns the day of the week (`0' is Monday) for YEAR (`1970'-...),
MONTH (`1'-`12'), DAY (`1'-`31').
`monthrange(year, month)'
Returns weekday of first day of the month and number of days in
month, for the specified YEAR and MONTH.
`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. Each week begins with Monday unless set by
`setfirstweekday()'.
`prmonth(theyear, themonth[, w[, l]])'
Prints a month's calendar as returned by `month()'.
`month(theyear, themonth[, w[, l]])'
Returns a month's calendar in a multi-line string. If W is
provided, it specifies the width of the date columns, which are
centered. If L is given, it specifies the number of lines that
each week will use. Depends on the first weekday as set by
`setfirstweekday()'.
`prcal(year[, w[, l[c]]])'
Prints the calendar for an entire year as returned by `calendar()'.
`calendar(year[, w[, l[c]]])'
Returns a 3-column calendar for an entire year as a multi-line
string. Optional parameters W, L, and 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
`setfirstweekday()'.
`timegm(tuple)'
An unrelated but handy function that takes a time tuple such as
returned by the `gmtime()' function in the `time' module, and
returns the corresponding Unix timestamp value, assuming an epoch
of 1970, and the POSIX encoding. In fact, `time.gmtime()' and
`timegm()' are each others' inverse.
See also:
Note:time Low-level time related functions.