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 | 1a670c8 | 2001-11-06 22:14:35 +0000 | [diff] [blame] | 5 | \modulesynopsis{Functions for working with calendars, |
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 |
Fred Drake | 1529ef8 | 2001-12-12 05:40:46 +0000 | [diff] [blame] | 15 | week to Sunday (6) or to any other weekday. Parameters that specify |
| 16 | dates are given as integers. |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 17 | |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 18 | Most of these functions and classses rely on the \module{datetime} |
| 19 | module which uses an idealized calendar, the current Gregorian |
| 20 | calendar indefinitely extended in both directions. This matches |
| 21 | the definition of the "proleptic Gregorian" calendar in Dershowitz |
| 22 | and Reingold's book "Calendrical Calculations", where it's the |
| 23 | base calendar for all computations. |
| 24 | |
| 25 | \begin{classdesc}{Calendar}{\optional{firstweekday}} |
| 26 | Creates a \class{Calendar} object. \var{firstweekday} is an integer |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 27 | specifying the first day of the week. \code{0} is Monday (the default), |
| 28 | \code{6} is Sunday. |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 29 | |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 30 | A \class{Calendar} object provides several methods that can |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 31 | be used for preparing the calendar data for formatting. This |
| 32 | class doesn't do any formatting itself. This is the job of |
| 33 | subclasses. |
| 34 | \versionadded{2.5} |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 35 | \end{classdesc} |
| 36 | |
| 37 | \class{Calendar} instances have the following methods: |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 38 | |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 39 | \begin{methoddesc}{iterweekdays}{weekday} |
| 40 | Return an iterator for the week day numbers that will be used |
| 41 | for one week. The first number from the iterator will be the |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 42 | same as the number returned by \method{firstweekday()}. |
| 43 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 44 | |
| 45 | \begin{methoddesc}{itermonthdates}{year, month} |
| 46 | Return an iterator for the month \var{month} (1-12) in the |
| 47 | year \var{year}. This iterator will return all days (as |
| 48 | \class{datetime.date} objects) for the month and all days |
| 49 | before the start of the month or after the end of the month |
| 50 | that are required to get a complete week. |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 51 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 52 | |
| 53 | \begin{methoddesc}{itermonthdays2}{year, month} |
| 54 | Return an iterator for the month \var{month} in the year |
| 55 | \var{year} similar to \method{itermonthdates()}. Days returned |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 56 | will be tuples consisting of a day number and a week day |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 57 | number. |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 58 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 59 | |
| 60 | \begin{methoddesc}{itermonthdays}{year, month} |
| 61 | Return an iterator for the month \var{month} in the year |
| 62 | \var{year} similar to \method{itermonthdates()}. Days returned |
| 63 | will simply be day numbers. |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 64 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 65 | |
| 66 | \begin{methoddesc}{monthdatescalendar}{year, month} |
| 67 | Return a list of the weeks in the month \var{month} of |
| 68 | the \var{year} as full weeks. Weeks are lists of seven |
| 69 | \class{datetime.date} objects. |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 70 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 71 | |
| 72 | \begin{methoddesc}{monthdays2calendar}{year, month} |
| 73 | Return a list of the weeks in the month \var{month} of |
| 74 | the \var{year} as full weeks. Weeks are lists of seven |
| 75 | tuples of day numbers and weekday numbers. |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 76 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 77 | |
| 78 | \begin{methoddesc}{monthdayscalendar}{year, month} |
| 79 | Return a list of the weeks in the month \var{month} of |
| 80 | the \var{year} as full weeks. Weeks are lists of seven |
| 81 | day numbers. |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 82 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 83 | |
| 84 | \begin{methoddesc}{yeardatescalendar}{year, month\optional{, width}} |
| 85 | Return the data for the specified year ready for formatting. The return |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 86 | value is a list of month rows. Each month row contains up to \var{width} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 87 | months (defaulting to 3). Each month contains between 4 and 6 weeks and |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 88 | each week contains 1--7 days. Days are \class{datetime.date} objects. |
| 89 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 90 | |
| 91 | \begin{methoddesc}{yeardays2calendar}{year, month\optional{, width}} |
| 92 | Return the data for the specified year ready for formatting (similar to |
| 93 | \method{yeardatescalendar()}). Entries in the week lists are tuples of |
| 94 | day numbers and weekday numbers. Day numbers outside this month are zero. |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 95 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 96 | |
| 97 | \begin{methoddesc}{yeardayscalendar}{year, month\optional{, width}} |
| 98 | Return the data for the specified year ready for formatting (similar to |
| 99 | \method{yeardatescalendar()}). Entries in the week lists are day numbers. |
| 100 | Day numbers outside this month are zero. |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 101 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 102 | |
| 103 | |
| 104 | \begin{classdesc}{TextCalendar}{\optional{firstweekday}} |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 105 | This class can be used to generate plain text calendars. |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 106 | |
| 107 | \versionadded{2.5} |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 108 | \end{classdesc} |
| 109 | |
| 110 | \class{TextCalendar} instances have the following methods: |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 111 | |
| 112 | \begin{methoddesc}{formatmonth}{theyear, themonth\optional{, w\optional{, l}}} |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 113 | Return a month's calendar in a multi-line string. If \var{w} is |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 114 | provided, it specifies the width of the date columns, which are |
| 115 | centered. If \var{l} is given, it specifies the number of lines that |
| 116 | each week will use. Depends on the first weekday as set by |
| 117 | \function{setfirstweekday()}. |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 118 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 119 | |
| 120 | \begin{methoddesc}{prmonth}{theyear, themonth\optional{, w\optional{, l}}} |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 121 | Print a month's calendar as returned by \method{formatmonth()}. |
| 122 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 123 | |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 124 | \begin{methoddesc}{formatyear}{theyear, themonth\optional{, w\optional{, |
| 125 | l\optional{, c\optional{, m}}}}} |
| 126 | Return a \var{m}-column calendar for an entire year as a multi-line string. |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 127 | Optional parameters \var{w}, \var{l}, and \var{c} are for date column |
| 128 | width, lines per week, and number of spaces between month columns, |
| 129 | respectively. Depends on the first weekday as set by |
| 130 | \method{setfirstweekday()}. The earliest year for which a calendar can |
| 131 | be generated is platform-dependent. |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 132 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 133 | |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 134 | \begin{methoddesc}{pryear}{theyear\optional{, w\optional{, l\optional{, |
| 135 | c\optional{, m}}}}} |
| 136 | Print the calendar for an entire year as returned by \method{formatyear()}. |
| 137 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 138 | |
| 139 | |
| 140 | \begin{classdesc}{HTMLCalendar}{\optional{firstweekday}} |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 141 | This class can be used to generate HTML calendars. |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 142 | |
| 143 | \versionadded{2.5} |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 144 | \end{classdesc} |
| 145 | |
| 146 | \class{HTMLCalendar} instances have the following methods: |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 147 | |
| 148 | \begin{methoddesc}{formatmonth}{theyear, themonth\optional{, withyear}} |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 149 | Return a month's calendar as an HTML table. If \var{withyear} is |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 150 | true the year will be included in the header, otherwise just the |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 151 | month name will be used. |
| 152 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 153 | |
| 154 | \begin{methoddesc}{formatyear}{theyear, themonth\optional{, width}} |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 155 | Return a year's calendar as an HTML table. \var{width} (defaulting to 3) |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 156 | specifies the number of months per row. |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 157 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 158 | |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 159 | \begin{methoddesc}{formatyearpage}{theyear, themonth\optional{, |
| 160 | width\optional{, css\optional{, encoding}}}} |
| 161 | Return a year's calendar as a complete HTML page. \var{width} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 162 | (defaulting to 3) specifies the number of months per row. \var{css} |
| 163 | is the name for the cascading style sheet to be used. \constant{None} |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 164 | can be passed if no style sheet should be used. \var{encoding} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 165 | specifies the encoding to be used for the output (defaulting |
Georg Brandl | 3bf538f | 2006-03-31 15:38:44 +0000 | [diff] [blame] | 166 | to the system default encoding). |
| 167 | \end{methoddesc} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 168 | |
| 169 | |
Walter Dörwald | 48d5e50 | 2006-04-01 07:57:00 +0000 | [diff] [blame] | 170 | \begin{classdesc}{LocaleTextCalendar}{\optional{firstweekday\optional{, locale}}} |
| 171 | This subclass of \class{TextCalendar} can be passed a locale name in the |
| 172 | constructor and will return month and weekday names in the specified locale. |
| 173 | If this locale includes an encoding all strings containing month and weekday |
| 174 | names will be returned as unicode. |
| 175 | \versionadded{2.5} |
| 176 | \end{classdesc} |
| 177 | |
| 178 | |
| 179 | \begin{classdesc}{LocaleHTMLCalendar}{\optional{firstweekday\optional{, locale}}} |
| 180 | This subclass of \class{HTMLCalendar} can be passed a locale name in the |
| 181 | constructor and will return month and weekday names in the specified locale. |
| 182 | If this locale includes an encoding all strings containing month and weekday |
| 183 | names will be returned as unicode. |
| 184 | \versionadded{2.5} |
| 185 | \end{classdesc} |
| 186 | |
| 187 | |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 188 | For simple text calendars this module provides the following functions. |
Neal Norwitz | 034c749 | 2002-11-03 00:13:42 +0000 | [diff] [blame] | 189 | |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 190 | \begin{funcdesc}{setfirstweekday}{weekday} |
| 191 | Sets the weekday (\code{0} is Monday, \code{6} is Sunday) to start |
| 192 | each week. The values \constant{MONDAY}, \constant{TUESDAY}, |
| 193 | \constant{WEDNESDAY}, \constant{THURSDAY}, \constant{FRIDAY}, |
| 194 | \constant{SATURDAY}, and \constant{SUNDAY} are provided for |
| 195 | convenience. For example, to set the first weekday to Sunday: |
| 196 | |
| 197 | \begin{verbatim} |
| 198 | import calendar |
| 199 | calendar.setfirstweekday(calendar.SUNDAY) |
| 200 | \end{verbatim} |
Fred Drake | e9996c6 | 2002-06-13 01:34:50 +0000 | [diff] [blame] | 201 | \versionadded{2.0} |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 202 | \end{funcdesc} |
| 203 | |
| 204 | \begin{funcdesc}{firstweekday}{} |
| 205 | Returns the current setting for the weekday to start each week. |
Fred Drake | e9996c6 | 2002-06-13 01:34:50 +0000 | [diff] [blame] | 206 | \versionadded{2.0} |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 207 | \end{funcdesc} |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 208 | |
| 209 | \begin{funcdesc}{isleap}{year} |
Fred Drake | ceb1fd2 | 2003-12-31 04:51:56 +0000 | [diff] [blame] | 210 | Returns \constant{True} if \var{year} is a leap year, otherwise |
| 211 | \constant{False}. |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 212 | \end{funcdesc} |
| 213 | |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 214 | \begin{funcdesc}{leapdays}{y1, y2} |
| 215 | Returns the number of leap years in the range |
Fred Drake | 1529ef8 | 2001-12-12 05:40:46 +0000 | [diff] [blame] | 216 | [\var{y1}\ldots\var{y2}), where \var{y1} and \var{y2} are years. |
Fred Drake | e9996c6 | 2002-06-13 01:34:50 +0000 | [diff] [blame] | 217 | \versionchanged[This function didn't work for ranges spanning |
| 218 | a century change in Python 1.5.2]{2.0} |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 219 | \end{funcdesc} |
| 220 | |
| 221 | \begin{funcdesc}{weekday}{year, month, day} |
| 222 | 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] | 223 | (\code{1970}--\ldots), \var{month} (\code{1}--\code{12}), \var{day} |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 224 | (\code{1}--\code{31}). |
| 225 | \end{funcdesc} |
| 226 | |
Walter Dörwald | e208412 | 2004-12-06 07:58:14 +0000 | [diff] [blame] | 227 | \begin{funcdesc}{weekheader}{n} |
| 228 | Return a header containing abbreviated weekday names. \var{n} specifies |
| 229 | the width in characters for one weekday. |
| 230 | \end{funcdesc} |
| 231 | |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 232 | \begin{funcdesc}{monthrange}{year, month} |
| 233 | Returns weekday of first day of the month and number of days in month, |
| 234 | for the specified \var{year} and \var{month}. |
| 235 | \end{funcdesc} |
| 236 | |
| 237 | \begin{funcdesc}{monthcalendar}{year, month} |
| 238 | Returns a matrix representing a month's calendar. Each row represents |
| 239 | a week; days outside of the month a represented by zeros. |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 240 | Each week begins with Monday unless set by \function{setfirstweekday()}. |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 241 | \end{funcdesc} |
| 242 | |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 243 | \begin{funcdesc}{prmonth}{theyear, themonth\optional{, w\optional{, l}}} |
| 244 | Prints a month's calendar as returned by \function{month()}. |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 245 | \end{funcdesc} |
| 246 | |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 247 | \begin{funcdesc}{month}{theyear, themonth\optional{, w\optional{, l}}} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 248 | Returns a month's calendar in a multi-line string using the |
| 249 | \method{formatmonth} of the \class{TextCalendar} class. |
Fred Drake | e9996c6 | 2002-06-13 01:34:50 +0000 | [diff] [blame] | 250 | \versionadded{2.0} |
Skip Montanaro | 7b828a6 | 2000-08-30 14:02:25 +0000 | [diff] [blame] | 251 | \end{funcdesc} |
| 252 | |
| 253 | \begin{funcdesc}{prcal}{year\optional{, w\optional{, l\optional{c}}}} |
| 254 | Prints the calendar for an entire year as returned by |
| 255 | \function{calendar()}. |
| 256 | \end{funcdesc} |
| 257 | |
| 258 | \begin{funcdesc}{calendar}{year\optional{, w\optional{, l\optional{c}}}} |
Walter Dörwald | 58917a6 | 2006-03-31 15:26:22 +0000 | [diff] [blame] | 259 | Returns a 3-column calendar for an entire year as a multi-line string |
| 260 | using the \method{formatyear} of the \class{TextCalendar} class. |
Fred Drake | e9996c6 | 2002-06-13 01:34:50 +0000 | [diff] [blame] | 261 | \versionadded{2.0} |
Fred Drake | 1c127e7 | 1998-04-28 14:28:57 +0000 | [diff] [blame] | 262 | \end{funcdesc} |
Guido van Rossum | 4727456 | 1999-06-09 15:11:58 +0000 | [diff] [blame] | 263 | |
| 264 | \begin{funcdesc}{timegm}{tuple} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 265 | An unrelated but handy function that takes a time tuple such as |
| 266 | returned by the \function{gmtime()} function in the \refmodule{time} |
Fred Drake | c37b65e | 2001-11-28 07:26:15 +0000 | [diff] [blame] | 267 | module, and returns the corresponding \UNIX{} timestamp value, assuming |
Guido van Rossum | 4727456 | 1999-06-09 15:11:58 +0000 | [diff] [blame] | 268 | an epoch of 1970, and the POSIX encoding. In fact, |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 269 | \function{time.gmtime()} and \function{timegm()} are each others' inverse. |
Fred Drake | e9996c6 | 2002-06-13 01:34:50 +0000 | [diff] [blame] | 270 | \versionadded{2.0} |
Guido van Rossum | 4727456 | 1999-06-09 15:11:58 +0000 | [diff] [blame] | 271 | \end{funcdesc} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 272 | |
Skip Montanaro | b80bad4 | 2005-01-05 07:13:32 +0000 | [diff] [blame] | 273 | The \module{calendar} module exports the following data attributes: |
| 274 | |
| 275 | \begin{datadesc}{day_name} |
| 276 | An array that represents the days of the week in the |
| 277 | current locale. |
| 278 | \end{datadesc} |
| 279 | |
| 280 | \begin{datadesc}{day_abbr} |
| 281 | An array that represents the abbreviated days of the week |
| 282 | in the current locale. |
| 283 | \end{datadesc} |
| 284 | |
| 285 | \begin{datadesc}{month_name} |
| 286 | An array that represents the months of the year in the |
| 287 | current locale. This follows normal convention |
| 288 | of January being month number 1, so it has a length of 13 and |
| 289 | \code{month_name[0]} is the empty string. |
| 290 | \end{datadesc} |
| 291 | |
| 292 | \begin{datadesc}{month_abbr} |
| 293 | An array that represents the abbreviated months of the year |
| 294 | in the current locale. This follows normal convention |
| 295 | of January being month number 1, so it has a length of 13 and |
| 296 | \code{month_abbr[0]} is the empty string. |
| 297 | \end{datadesc} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 298 | |
| 299 | \begin{seealso} |
Fred Drake | ceb1fd2 | 2003-12-31 04:51:56 +0000 | [diff] [blame] | 300 | \seemodule{datetime}{Object-oriented interface to dates and times |
| 301 | with similar functionality to the |
| 302 | \refmodule{time} module.} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 303 | \seemodule{time}{Low-level time related functions.} |
| 304 | \end{seealso} |