Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | :mod:`calendar` --- General calendar-related functions |
| 2 | ====================================================== |
| 3 | |
| 4 | .. module:: calendar |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 5 | :synopsis: Functions for working with calendars, including some emulation |
| 6 | of the Unix cal program. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 7 | .. sectionauthor:: Drew Csillag <drew_csillag@geocities.com> |
| 8 | |
Raymond Hettinger | 1048094 | 2011-01-10 03:26:08 +0000 | [diff] [blame] | 9 | **Source code:** :source:`Lib/calendar.py` |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 10 | |
Raymond Hettinger | 4f707fd | 2011-01-10 19:54:11 +0000 | [diff] [blame] | 11 | -------------- |
| 12 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 13 | This module allows you to output calendars like the Unix :program:`cal` program, |
| 14 | and provides additional useful functions related to the calendar. By default, |
| 15 | these calendars have Monday as the first day of the week, and Sunday as the last |
| 16 | (the European convention). Use :func:`setfirstweekday` to set the first day of |
| 17 | the week to Sunday (6) or to any other weekday. Parameters that specify dates |
| 18 | are given as integers. For related |
| 19 | functionality, see also the :mod:`datetime` and :mod:`time` modules. |
| 20 | |
Benjamin Peterson | d7c3ed5 | 2010-06-27 22:32:30 +0000 | [diff] [blame] | 21 | Most of these functions and classes rely on the :mod:`datetime` module which |
Alexander Belopolsky | d4bbab2 | 2010-11-22 03:06:56 +0000 | [diff] [blame] | 22 | uses an idealized calendar, the current Gregorian calendar extended |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 23 | in both directions. This matches the definition of the "proleptic Gregorian" |
| 24 | calendar in Dershowitz and Reingold's book "Calendrical Calculations", where |
| 25 | it's the base calendar for all computations. |
| 26 | |
| 27 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 28 | .. class:: Calendar(firstweekday=0) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 29 | |
| 30 | Creates a :class:`Calendar` object. *firstweekday* is an integer specifying the |
| 31 | first day of the week. ``0`` is Monday (the default), ``6`` is Sunday. |
| 32 | |
| 33 | A :class:`Calendar` object provides several methods that can be used for |
| 34 | preparing the calendar data for formatting. This class doesn't do any formatting |
| 35 | itself. This is the job of subclasses. |
| 36 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 37 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 38 | :class:`Calendar` instances have the following methods: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 39 | |
Alexandre Vassalotti | bee3253 | 2008-05-16 18:15:12 +0000 | [diff] [blame] | 40 | .. method:: iterweekdays() |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 41 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 42 | Return an iterator for the week day numbers that will be used for one |
| 43 | week. The first value from the iterator will be the same as the value of |
| 44 | the :attr:`firstweekday` property. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 45 | |
| 46 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 47 | .. method:: itermonthdates(year, month) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 48 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 49 | Return an iterator for the month *month* (1-12) in the year *year*. This |
| 50 | iterator will return all days (as :class:`datetime.date` objects) for the |
| 51 | month and all days before the start of the month or after the end of the |
| 52 | month that are required to get a complete week. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 53 | |
| 54 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 55 | .. method:: itermonthdays2(year, month) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 56 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 57 | Return an iterator for the month *month* in the year *year* similar to |
| 58 | :meth:`itermonthdates`. Days returned will be tuples consisting of a day |
| 59 | number and a week day number. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 60 | |
| 61 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 62 | .. method:: itermonthdays(year, month) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 63 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 64 | Return an iterator for the month *month* in the year *year* similar to |
| 65 | :meth:`itermonthdates`. Days returned will simply be day numbers. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 66 | |
| 67 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 68 | .. method:: monthdatescalendar(year, month) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 69 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 70 | Return a list of the weeks in the month *month* of the *year* as full |
| 71 | weeks. Weeks are lists of seven :class:`datetime.date` objects. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 72 | |
| 73 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 74 | .. method:: monthdays2calendar(year, month) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 75 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 76 | Return a list of the weeks in the month *month* of the *year* as full |
| 77 | weeks. Weeks are lists of seven tuples of day numbers and weekday |
| 78 | numbers. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 79 | |
| 80 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 81 | .. method:: monthdayscalendar(year, month) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 82 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 83 | Return a list of the weeks in the month *month* of the *year* as full |
| 84 | weeks. Weeks are lists of seven day numbers. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 85 | |
| 86 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 87 | .. method:: yeardatescalendar(year, width=3) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 88 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 89 | Return the data for the specified year ready for formatting. The return |
| 90 | value is a list of month rows. Each month row contains up to *width* |
| 91 | months (defaulting to 3). Each month contains between 4 and 6 weeks and |
| 92 | each week contains 1--7 days. Days are :class:`datetime.date` objects. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 93 | |
| 94 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 95 | .. method:: yeardays2calendar(year, width=3) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 96 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 97 | Return the data for the specified year ready for formatting (similar to |
| 98 | :meth:`yeardatescalendar`). Entries in the week lists are tuples of day |
| 99 | numbers and weekday numbers. Day numbers outside this month are zero. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 100 | |
| 101 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 102 | .. method:: yeardayscalendar(year, width=3) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 103 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 104 | Return the data for the specified year ready for formatting (similar to |
| 105 | :meth:`yeardatescalendar`). Entries in the week lists are day numbers. Day |
| 106 | numbers outside this month are zero. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 107 | |
| 108 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 109 | .. class:: TextCalendar(firstweekday=0) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 110 | |
| 111 | This class can be used to generate plain text calendars. |
| 112 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 113 | :class:`TextCalendar` instances have the following methods: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 114 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 115 | .. method:: formatmonth(theyear, themonth, w=0, l=0) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 116 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 117 | Return a month's calendar in a multi-line string. If *w* is provided, it |
| 118 | specifies the width of the date columns, which are centered. If *l* is |
| 119 | given, it specifies the number of lines that each week will use. Depends |
| 120 | on the first weekday as specified in the constructor or set by the |
| 121 | :meth:`setfirstweekday` method. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 122 | |
| 123 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 124 | .. method:: prmonth(theyear, themonth, w=0, l=0) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 125 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 126 | Print a month's calendar as returned by :meth:`formatmonth`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 127 | |
| 128 | |
Benjamin Peterson | 2021100 | 2009-11-25 18:34:42 +0000 | [diff] [blame] | 129 | .. method:: formatyear(theyear, w=2, l=1, c=6, m=3) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 130 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 131 | Return a *m*-column calendar for an entire year as a multi-line string. |
| 132 | Optional parameters *w*, *l*, and *c* are for date column width, lines per |
| 133 | week, and number of spaces between month columns, respectively. Depends on |
| 134 | the first weekday as specified in the constructor or set by the |
| 135 | :meth:`setfirstweekday` method. The earliest year for which a calendar |
| 136 | can be generated is platform-dependent. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 137 | |
| 138 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 139 | .. method:: pryear(theyear, w=2, l=1, c=6, m=3) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 140 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 141 | Print the calendar for an entire year as returned by :meth:`formatyear`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 142 | |
| 143 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 144 | .. class:: HTMLCalendar(firstweekday=0) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 145 | |
| 146 | This class can be used to generate HTML calendars. |
| 147 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 148 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 149 | :class:`HTMLCalendar` instances have the following methods: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 150 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 151 | .. method:: formatmonth(theyear, themonth, withyear=True) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 152 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 153 | Return a month's calendar as an HTML table. If *withyear* is true the year |
| 154 | will be included in the header, otherwise just the month name will be |
| 155 | used. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 156 | |
| 157 | |
Benjamin Peterson | 2021100 | 2009-11-25 18:34:42 +0000 | [diff] [blame] | 158 | .. method:: formatyear(theyear, width=3) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 159 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 160 | Return a year's calendar as an HTML table. *width* (defaulting to 3) |
| 161 | specifies the number of months per row. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 162 | |
| 163 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 164 | .. method:: formatyearpage(theyear, width=3, css='calendar.css', encoding=None) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 165 | |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 166 | Return a year's calendar as a complete HTML page. *width* (defaulting to |
| 167 | 3) specifies the number of months per row. *css* is the name for the |
| 168 | cascading style sheet to be used. :const:`None` can be passed if no style |
| 169 | sheet should be used. *encoding* specifies the encoding to be used for the |
| 170 | output (defaulting to the system default encoding). |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 171 | |
| 172 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 173 | .. class:: LocaleTextCalendar(firstweekday=0, locale=None) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 174 | |
| 175 | This subclass of :class:`TextCalendar` can be passed a locale name in the |
Georg Brandl | 7004bd1 | 2010-10-19 18:54:25 +0000 | [diff] [blame] | 176 | constructor and will return month and weekday names in the specified locale. |
| 177 | If this locale includes an encoding all strings containing month and weekday |
| 178 | names will be returned as unicode. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 179 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 180 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 181 | .. class:: LocaleHTMLCalendar(firstweekday=0, locale=None) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 182 | |
| 183 | This subclass of :class:`HTMLCalendar` can be passed a locale name in the |
Benjamin Peterson | e41251e | 2008-04-25 01:59:09 +0000 | [diff] [blame] | 184 | constructor and will return month and weekday names in the specified |
| 185 | locale. If this locale includes an encoding all strings containing month and |
| 186 | weekday names will be returned as unicode. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 187 | |
Georg Brandl | 7004bd1 | 2010-10-19 18:54:25 +0000 | [diff] [blame] | 188 | .. note:: |
| 189 | |
| 190 | The :meth:`formatweekday` and :meth:`formatmonthname` methods of these two |
| 191 | classes temporarily change the current locale to the given *locale*. Because |
| 192 | the current locale is a process-wide setting, they are not thread-safe. |
| 193 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 194 | |
| 195 | For simple text calendars this module provides the following functions. |
| 196 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 197 | .. function:: setfirstweekday(weekday) |
| 198 | |
| 199 | Sets the weekday (``0`` is Monday, ``6`` is Sunday) to start each week. The |
| 200 | values :const:`MONDAY`, :const:`TUESDAY`, :const:`WEDNESDAY`, :const:`THURSDAY`, |
| 201 | :const:`FRIDAY`, :const:`SATURDAY`, and :const:`SUNDAY` are provided for |
| 202 | convenience. For example, to set the first weekday to Sunday:: |
| 203 | |
| 204 | import calendar |
| 205 | calendar.setfirstweekday(calendar.SUNDAY) |
| 206 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 207 | |
| 208 | .. function:: firstweekday() |
| 209 | |
| 210 | Returns the current setting for the weekday to start each week. |
| 211 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 212 | |
| 213 | .. function:: isleap(year) |
| 214 | |
| 215 | Returns :const:`True` if *year* is a leap year, otherwise :const:`False`. |
| 216 | |
| 217 | |
| 218 | .. function:: leapdays(y1, y2) |
| 219 | |
| 220 | Returns the number of leap years in the range from *y1* to *y2* (exclusive), |
| 221 | where *y1* and *y2* are years. |
| 222 | |
Georg Brandl | 55ac8f0 | 2007-09-01 13:51:09 +0000 | [diff] [blame] | 223 | This function works for ranges spanning a century change. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 224 | |
| 225 | |
| 226 | .. function:: weekday(year, month, day) |
| 227 | |
| 228 | Returns the day of the week (``0`` is Monday) for *year* (``1970``--...), |
| 229 | *month* (``1``--``12``), *day* (``1``--``31``). |
| 230 | |
| 231 | |
| 232 | .. function:: weekheader(n) |
| 233 | |
| 234 | Return a header containing abbreviated weekday names. *n* specifies the width in |
| 235 | characters for one weekday. |
| 236 | |
| 237 | |
| 238 | .. function:: monthrange(year, month) |
| 239 | |
| 240 | Returns weekday of first day of the month and number of days in month, for the |
| 241 | specified *year* and *month*. |
| 242 | |
| 243 | |
| 244 | .. function:: monthcalendar(year, month) |
| 245 | |
| 246 | Returns a matrix representing a month's calendar. Each row represents a week; |
| 247 | days outside of the month a represented by zeros. Each week begins with Monday |
| 248 | unless set by :func:`setfirstweekday`. |
| 249 | |
| 250 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 251 | .. function:: prmonth(theyear, themonth, w=0, l=0) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 252 | |
| 253 | Prints a month's calendar as returned by :func:`month`. |
| 254 | |
| 255 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 256 | .. function:: month(theyear, themonth, w=0, l=0) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 257 | |
| 258 | Returns a month's calendar in a multi-line string using the :meth:`formatmonth` |
| 259 | of the :class:`TextCalendar` class. |
| 260 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 261 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 262 | .. function:: prcal(year, w=0, l=0, c=6, m=3) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 263 | |
| 264 | Prints the calendar for an entire year as returned by :func:`calendar`. |
| 265 | |
| 266 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 267 | .. function:: calendar(year, w=2, l=1, c=6, m=3) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 268 | |
Georg Brandl | 0d8f073 | 2009-04-05 22:20:44 +0000 | [diff] [blame] | 269 | Returns a 3-column calendar for an entire year as a multi-line string using |
| 270 | the :meth:`formatyear` of the :class:`TextCalendar` class. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 271 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 272 | |
| 273 | .. function:: timegm(tuple) |
| 274 | |
| 275 | An unrelated but handy function that takes a time tuple such as returned by the |
| 276 | :func:`gmtime` function in the :mod:`time` module, and returns the corresponding |
| 277 | Unix timestamp value, assuming an epoch of 1970, and the POSIX encoding. In |
| 278 | fact, :func:`time.gmtime` and :func:`timegm` are each others' inverse. |
| 279 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 280 | |
| 281 | The :mod:`calendar` module exports the following data attributes: |
| 282 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 283 | .. data:: day_name |
| 284 | |
| 285 | An array that represents the days of the week in the current locale. |
| 286 | |
| 287 | |
| 288 | .. data:: day_abbr |
| 289 | |
| 290 | An array that represents the abbreviated days of the week in the current locale. |
| 291 | |
| 292 | |
| 293 | .. data:: month_name |
| 294 | |
| 295 | An array that represents the months of the year in the current locale. This |
| 296 | follows normal convention of January being month number 1, so it has a length of |
| 297 | 13 and ``month_name[0]`` is the empty string. |
| 298 | |
| 299 | |
| 300 | .. data:: month_abbr |
| 301 | |
| 302 | An array that represents the abbreviated months of the year in the current |
| 303 | locale. This follows normal convention of January being month number 1, so it |
| 304 | has a length of 13 and ``month_abbr[0]`` is the empty string. |
| 305 | |
| 306 | |
| 307 | .. seealso:: |
| 308 | |
| 309 | Module :mod:`datetime` |
| 310 | Object-oriented interface to dates and times with similar functionality to the |
| 311 | :mod:`time` module. |
| 312 | |
| 313 | Module :mod:`time` |
| 314 | Low-level time related functions. |