2007-08-15 11:28:22 -03:00
|
|
|
:mod:`calendar` --- General calendar-related functions
|
|
|
|
======================================================
|
|
|
|
|
|
|
|
.. module:: calendar
|
2009-04-05 19:20:44 -03:00
|
|
|
:synopsis: Functions for working with calendars, including some emulation
|
|
|
|
of the Unix cal program.
|
2007-08-15 11:28:22 -03:00
|
|
|
.. sectionauthor:: Drew Csillag <drew_csillag@geocities.com>
|
|
|
|
|
2011-01-09 23:26:08 -04:00
|
|
|
**Source code:** :source:`Lib/calendar.py`
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-01-10 15:54:11 -04:00
|
|
|
--------------
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
This module allows you to output calendars like the Unix :program:`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 :func:`setfirstweekday` to set the first day of
|
|
|
|
the week to Sunday (6) or to any other weekday. Parameters that specify dates
|
|
|
|
are given as integers. For related
|
|
|
|
functionality, see also the :mod:`datetime` and :mod:`time` modules.
|
|
|
|
|
Merged revisions 80605-80609,80642-80646,80651-80652,80674,80684-80686,80748,80852,80854,80870,80872-80873,80907,80915-80916,80951-80952,80976-80977,80985,81038-81040,81042,81053,81070,81104-81105,81114,81125,81245,81285,81402,81463,81516,81562-81563,81567,81593,81635,81680-81681,81684,81801,81888,81931-81933,81939-81942,81963,81984,81991,82120,82188,82264-82267 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80605 | andrew.kuchling | 2010-04-28 19:22:16 -0500 (Wed, 28 Apr 2010) | 1 line
Add various items
........
r80606 | andrew.kuchling | 2010-04-28 20:44:30 -0500 (Wed, 28 Apr 2010) | 6 lines
Fix doubled 'the'.
Markup fixes to use :exc:, :option: in a few places.
(Glitch: unittest.main's -c ends up a link to the Python
interpreter's -c option. Should we skip using :option: for that
switch, or disable the auto-linking somehow?)
........
r80607 | andrew.kuchling | 2010-04-28 20:45:41 -0500 (Wed, 28 Apr 2010) | 1 line
Add various unittest items
........
r80608 | benjamin.peterson | 2010-04-28 22:18:05 -0500 (Wed, 28 Apr 2010) | 1 line
update pypy description
........
r80609 | benjamin.peterson | 2010-04-28 22:30:59 -0500 (Wed, 28 Apr 2010) | 1 line
update pypy url
........
r80642 | andrew.kuchling | 2010-04-29 19:49:09 -0500 (Thu, 29 Apr 2010) | 1 line
Always add space after RFC; reword paragraph
........
r80643 | andrew.kuchling | 2010-04-29 19:52:31 -0500 (Thu, 29 Apr 2010) | 6 lines
Reword paragraph to make its meaning clearer.
Antoine Pitrou: is my version of the paragraph still correct?
R. David Murray: is this more understandable than the previous version?
........
r80644 | andrew.kuchling | 2010-04-29 20:02:15 -0500 (Thu, 29 Apr 2010) | 1 line
Fix typos
........
r80645 | andrew.kuchling | 2010-04-29 20:32:47 -0500 (Thu, 29 Apr 2010) | 1 line
Markup fix; clarify by adding 'in that order'
........
r80646 | andrew.kuchling | 2010-04-29 20:33:40 -0500 (Thu, 29 Apr 2010) | 1 line
Add various items; rearrange unittest section a bit
........
r80651 | andrew.kuchling | 2010-04-30 08:46:55 -0500 (Fri, 30 Apr 2010) | 1 line
Minor grammar re-wording
........
r80652 | andrew.kuchling | 2010-04-30 08:47:34 -0500 (Fri, 30 Apr 2010) | 1 line
Add item
........
r80674 | andrew.kuchling | 2010-04-30 20:19:16 -0500 (Fri, 30 Apr 2010) | 1 line
Add various items
........
r80684 | andrew.kuchling | 2010-05-01 07:05:52 -0500 (Sat, 01 May 2010) | 1 line
Minor grammar fix
........
r80685 | andrew.kuchling | 2010-05-01 07:06:51 -0500 (Sat, 01 May 2010) | 1 line
Describe memoryview
........
r80686 | antoine.pitrou | 2010-05-01 07:16:39 -0500 (Sat, 01 May 2010) | 4 lines
Fix attribution. Travis didn't do much and he did a bad work.
(yes, this is a sensitive subject, sorry)
........
r80748 | andrew.kuchling | 2010-05-03 20:24:22 -0500 (Mon, 03 May 2010) | 1 line
Add some more items; the urlparse change is added twice
........
r80852 | andrew.kuchling | 2010-05-05 20:09:47 -0500 (Wed, 05 May 2010) | 1 line
Reword paragraph; fix filename, which should be pyconfig.h
........
r80854 | andrew.kuchling | 2010-05-05 20:10:56 -0500 (Wed, 05 May 2010) | 1 line
Add various items
........
r80870 | andrew.kuchling | 2010-05-06 09:14:09 -0500 (Thu, 06 May 2010) | 1 line
Describe ElementTree 1.3; rearrange new-module sections; describe dict views as sets; small edits and items
........
r80872 | andrew.kuchling | 2010-05-06 12:21:59 -0500 (Thu, 06 May 2010) | 1 line
Add 2 items; record ideas for two initial sections; clarify wording
........
r80873 | andrew.kuchling | 2010-05-06 12:27:57 -0500 (Thu, 06 May 2010) | 1 line
Change section title; point to unittest2
........
r80907 | andrew.kuchling | 2010-05-06 20:45:14 -0500 (Thu, 06 May 2010) | 1 line
Add a new section on the development plan; add an item
........
r80915 | antoine.pitrou | 2010-05-07 05:15:51 -0500 (Fri, 07 May 2010) | 3 lines
Fix some markup and a class name. Also, wrap a long line.
........
r80916 | andrew.kuchling | 2010-05-07 06:30:47 -0500 (Fri, 07 May 2010) | 1 line
Re-word text
........
r80951 | andrew.kuchling | 2010-05-07 20:15:26 -0500 (Fri, 07 May 2010) | 1 line
Add two items
........
r80952 | andrew.kuchling | 2010-05-07 20:35:55 -0500 (Fri, 07 May 2010) | 1 line
Get accents correct
........
r80976 | andrew.kuchling | 2010-05-08 08:28:03 -0500 (Sat, 08 May 2010) | 1 line
Add logging.dictConfig example; give up on writing a Ttk example
........
r80977 | andrew.kuchling | 2010-05-08 08:29:46 -0500 (Sat, 08 May 2010) | 1 line
Markup fixes
........
r80985 | andrew.kuchling | 2010-05-08 10:39:46 -0500 (Sat, 08 May 2010) | 7 lines
Write summary of the 2.7 release; rewrite the future section some more;
mention PYTHONWARNINGS env. var; tweak some examples for readability.
And with this commit, the "What's New" is done... except for a
complete read-through to polish the text, and fixing any reported errors,
but those tasks can easily wait until after beta2.
........
r81038 | benjamin.peterson | 2010-05-09 16:09:40 -0500 (Sun, 09 May 2010) | 1 line
finish clause
........
r81039 | andrew.kuchling | 2010-05-10 09:18:27 -0500 (Mon, 10 May 2010) | 1 line
Markup fix; re-word a sentence
........
r81040 | andrew.kuchling | 2010-05-10 09:20:12 -0500 (Mon, 10 May 2010) | 1 line
Use title case
........
r81042 | andrew.kuchling | 2010-05-10 10:03:35 -0500 (Mon, 10 May 2010) | 1 line
Link to unittest2 article
........
r81053 | florent.xicluna | 2010-05-10 14:59:22 -0500 (Mon, 10 May 2010) | 2 lines
Add a link on maketrans().
........
r81070 | andrew.kuchling | 2010-05-10 18:13:41 -0500 (Mon, 10 May 2010) | 1 line
Fix typo
........
r81104 | andrew.kuchling | 2010-05-11 19:38:44 -0500 (Tue, 11 May 2010) | 1 line
Revision pass: lots of edits, typo fixes, rearrangements
........
r81105 | andrew.kuchling | 2010-05-11 19:40:47 -0500 (Tue, 11 May 2010) | 1 line
Let's call this done
........
r81114 | andrew.kuchling | 2010-05-12 08:56:07 -0500 (Wed, 12 May 2010) | 1 line
Grammar fix
........
r81125 | andrew.kuchling | 2010-05-12 13:56:48 -0500 (Wed, 12 May 2010) | 1 line
#8696: add documentation for logging.config.dictConfig (PEP 391)
........
r81245 | andrew.kuchling | 2010-05-16 18:31:16 -0500 (Sun, 16 May 2010) | 1 line
Add cross-reference to later section
........
r81285 | vinay.sajip | 2010-05-18 03:16:27 -0500 (Tue, 18 May 2010) | 1 line
Fixed minor typo in ReST markup.
........
r81402 | vinay.sajip | 2010-05-21 12:41:34 -0500 (Fri, 21 May 2010) | 1 line
Updated logging documentation with more dictConfig information.
........
r81463 | georg.brandl | 2010-05-22 03:17:23 -0500 (Sat, 22 May 2010) | 1 line
#8785: less confusing description of regex.find*.
........
r81516 | andrew.kuchling | 2010-05-25 08:34:08 -0500 (Tue, 25 May 2010) | 1 line
Add three items
........
r81562 | andrew.kuchling | 2010-05-27 08:22:53 -0500 (Thu, 27 May 2010) | 1 line
Rewrite wxWidgets section
........
r81563 | andrew.kuchling | 2010-05-27 08:30:09 -0500 (Thu, 27 May 2010) | 1 line
Remove top-level 'General Questions' section, pushing up the questions it contains
........
r81567 | andrew.kuchling | 2010-05-27 16:29:59 -0500 (Thu, 27 May 2010) | 1 line
Add item
........
r81593 | georg.brandl | 2010-05-29 03:46:18 -0500 (Sat, 29 May 2010) | 1 line
#8616: add new turtle demo "nim".
........
r81635 | georg.brandl | 2010-06-01 02:25:23 -0500 (Tue, 01 Jun 2010) | 1 line
Put docs for RegexObject.search() before RegexObject.match() to mirror re.search() and re.match() order.
........
r81680 | vinay.sajip | 2010-06-03 17:34:42 -0500 (Thu, 03 Jun 2010) | 1 line
Issue #8890: Documentation changed to avoid reference to temporary files.
........
r81681 | sean.reifschneider | 2010-06-03 20:51:26 -0500 (Thu, 03 Jun 2010) | 2 lines
Issue8810: Clearing up docstring for tzinfo.utcoffset.
........
r81684 | vinay.sajip | 2010-06-04 08:41:02 -0500 (Fri, 04 Jun 2010) | 1 line
Issue #8890: Documentation changed to avoid reference to temporary files - other cases covered.
........
r81801 | andrew.kuchling | 2010-06-07 08:38:40 -0500 (Mon, 07 Jun 2010) | 1 line
#8875: Remove duplicated paragraph
........
r81888 | andrew.kuchling | 2010-06-10 20:54:58 -0500 (Thu, 10 Jun 2010) | 1 line
Add a few more items
........
r81931 | georg.brandl | 2010-06-12 01:26:54 -0500 (Sat, 12 Jun 2010) | 1 line
Fix punctuation.
........
r81932 | georg.brandl | 2010-06-12 01:28:58 -0500 (Sat, 12 Jun 2010) | 1 line
Document that an existing directory raises in mkdir().
........
r81933 | georg.brandl | 2010-06-12 01:45:33 -0500 (Sat, 12 Jun 2010) | 1 line
Update version in README.
........
r81939 | georg.brandl | 2010-06-12 04:45:01 -0500 (Sat, 12 Jun 2010) | 1 line
Use newer toctree syntax.
........
r81940 | georg.brandl | 2010-06-12 04:45:28 -0500 (Sat, 12 Jun 2010) | 1 line
Add document on how to build.
........
r81941 | georg.brandl | 2010-06-12 04:45:58 -0500 (Sat, 12 Jun 2010) | 1 line
Fix gratuitous indentation.
........
r81942 | georg.brandl | 2010-06-12 04:46:03 -0500 (Sat, 12 Jun 2010) | 1 line
Update README.
........
r81963 | andrew.kuchling | 2010-06-12 15:00:55 -0500 (Sat, 12 Jun 2010) | 1 line
Grammar fix
........
r81984 | georg.brandl | 2010-06-14 10:58:39 -0500 (Mon, 14 Jun 2010) | 1 line
#8993: fix reference.
........
r81991 | andrew.kuchling | 2010-06-14 19:38:58 -0500 (Mon, 14 Jun 2010) | 1 line
Add another bunch of items
........
r82120 | andrew.kuchling | 2010-06-20 16:45:45 -0500 (Sun, 20 Jun 2010) | 1 line
Note that Python 3.x isn't covered; add forward ref. for UTF-8; note error in 2.5 and up
........
r82188 | benjamin.peterson | 2010-06-23 19:02:46 -0500 (Wed, 23 Jun 2010) | 1 line
remove reverted changed
........
r82264 | georg.brandl | 2010-06-27 05:47:47 -0500 (Sun, 27 Jun 2010) | 1 line
Confusing punctuation.
........
r82265 | georg.brandl | 2010-06-27 05:49:23 -0500 (Sun, 27 Jun 2010) | 1 line
Use designated syntax for optional grammar element.
........
r82266 | georg.brandl | 2010-06-27 05:51:44 -0500 (Sun, 27 Jun 2010) | 1 line
Fix URL.
........
r82267 | georg.brandl | 2010-06-27 05:55:38 -0500 (Sun, 27 Jun 2010) | 1 line
Two typos.
........
2010-06-27 19:32:30 -03:00
|
|
|
Most of these functions and classes rely on the :mod:`datetime` module which
|
2010-11-21 23:06:56 -04:00
|
|
|
uses an idealized calendar, the current Gregorian calendar extended
|
2007-08-15 11:28:22 -03:00
|
|
|
in both directions. This matches the definition of the "proleptic Gregorian"
|
|
|
|
calendar in Dershowitz and Reingold's book "Calendrical Calculations", where
|
|
|
|
it's the base calendar for all computations.
|
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. class:: Calendar(firstweekday=0)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Creates a :class:`Calendar` object. *firstweekday* is an integer specifying the
|
|
|
|
first day of the week. ``0`` is Monday (the default), ``6`` is Sunday.
|
|
|
|
|
|
|
|
A :class:`Calendar` object provides several methods that can be used for
|
|
|
|
preparing the calendar data for formatting. This class doesn't do any formatting
|
|
|
|
itself. This is the job of subclasses.
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
:class:`Calendar` instances have the following methods:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
Merged revisions 63361-63373,63375,63377-63380 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63361 | alexandre.vassalotti | 2008-05-16 03:14:08 -0400 (Fri, 16 May 2008) | 2 lines
Rename the test file of reprlib.
........
r63364 | georg.brandl | 2008-05-16 05:34:48 -0400 (Fri, 16 May 2008) | 2 lines
Make generator repr consistent with function and code object repr.
........
r63365 | georg.brandl | 2008-05-16 05:47:29 -0400 (Fri, 16 May 2008) | 2 lines
#2869: remove parameter from signature.
........
r63366 | christian.heimes | 2008-05-16 06:23:31 -0400 (Fri, 16 May 2008) | 1 line
Fixed #2870: cmathmodule.c compile error
........
r63367 | christian.heimes | 2008-05-16 07:28:56 -0400 (Fri, 16 May 2008) | 1 line
Following Amaury's advice
........
r63368 | georg.brandl | 2008-05-16 09:10:15 -0400 (Fri, 16 May 2008) | 2 lines
#2890: support os.O_ASYNC and fcntl.FASYNC.
........
r63369 | georg.brandl | 2008-05-16 09:18:50 -0400 (Fri, 16 May 2008) | 2 lines
#2845: fix copy2's docs.
........
r63370 | georg.brandl | 2008-05-16 09:24:29 -0400 (Fri, 16 May 2008) | 2 lines
Don't allow keyword arguments to reversed().
........
r63373 | georg.brandl | 2008-05-16 09:41:26 -0400 (Fri, 16 May 2008) | 2 lines
Document O_ASYNC addition.
........
r63380 | georg.brandl | 2008-05-16 13:33:13 -0400 (Fri, 16 May 2008) | 2 lines
Fix reprlib docs.
........
2008-05-16 15:15:12 -03:00
|
|
|
.. method:: iterweekdays()
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return an iterator for the week day numbers that will be used for one
|
|
|
|
week. The first value from the iterator will be the same as the value of
|
|
|
|
the :attr:`firstweekday` property.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
.. method:: itermonthdates(year, month)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return an iterator for the month *month* (1-12) in the year *year*. This
|
|
|
|
iterator will return all days (as :class:`datetime.date` objects) for the
|
|
|
|
month and all days before the start of the month or after the end of the
|
|
|
|
month that are required to get a complete week.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
.. method:: itermonthdays2(year, month)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return an iterator for the month *month* in the year *year* similar to
|
|
|
|
:meth:`itermonthdates`. Days returned will be tuples consisting of a day
|
|
|
|
number and a week day number.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
.. method:: itermonthdays(year, month)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return an iterator for the month *month* in the year *year* similar to
|
|
|
|
:meth:`itermonthdates`. Days returned will simply be day numbers.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
.. method:: monthdatescalendar(year, month)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return a list of the weeks in the month *month* of the *year* as full
|
|
|
|
weeks. Weeks are lists of seven :class:`datetime.date` objects.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
.. method:: monthdays2calendar(year, month)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return a list of the weeks in the month *month* of the *year* as full
|
|
|
|
weeks. Weeks are lists of seven tuples of day numbers and weekday
|
|
|
|
numbers.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
.. method:: monthdayscalendar(year, month)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return a list of the weeks in the month *month* of the *year* as full
|
|
|
|
weeks. Weeks are lists of seven day numbers.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. method:: yeardatescalendar(year, width=3)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return the data for the specified year ready for formatting. The return
|
|
|
|
value is a list of month rows. Each month row contains up to *width*
|
|
|
|
months (defaulting to 3). Each month contains between 4 and 6 weeks and
|
|
|
|
each week contains 1--7 days. Days are :class:`datetime.date` objects.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. method:: yeardays2calendar(year, width=3)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return the data for the specified year ready for formatting (similar to
|
|
|
|
:meth:`yeardatescalendar`). Entries in the week lists are tuples of day
|
|
|
|
numbers and weekday numbers. Day numbers outside this month are zero.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. method:: yeardayscalendar(year, width=3)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return the data for the specified year ready for formatting (similar to
|
|
|
|
:meth:`yeardatescalendar`). Entries in the week lists are day numbers. Day
|
|
|
|
numbers outside this month are zero.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. class:: TextCalendar(firstweekday=0)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
This class can be used to generate plain text calendars.
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
:class:`TextCalendar` instances have the following methods:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. method:: formatmonth(theyear, themonth, w=0, l=0)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return 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 specified in the constructor or set by the
|
|
|
|
:meth:`setfirstweekday` method.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. method:: prmonth(theyear, themonth, w=0, l=0)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Print a month's calendar as returned by :meth:`formatmonth`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
Merged revisions 76259,76326,76376-76377,76430,76471,76517 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r76259 | georg.brandl | 2009-11-14 05:50:51 -0600 (Sat, 14 Nov 2009) | 1 line
Fix terminology.
................
r76326 | georg.brandl | 2009-11-16 10:44:05 -0600 (Mon, 16 Nov 2009) | 1 line
#7302: fix link.
................
r76376 | georg.brandl | 2009-11-18 13:39:14 -0600 (Wed, 18 Nov 2009) | 1 line
upcase Python
................
r76377 | georg.brandl | 2009-11-18 14:05:15 -0600 (Wed, 18 Nov 2009) | 1 line
Fix markup.
................
r76430 | r.david.murray | 2009-11-20 07:29:43 -0600 (Fri, 20 Nov 2009) | 2 lines
Issue 7363: fix indentation in socketserver udpserver example.
................
r76471 | georg.brandl | 2009-11-23 13:53:19 -0600 (Mon, 23 Nov 2009) | 1 line
#7345: fix arguments of formatyear().
................
r76517 | benjamin.peterson | 2009-11-25 12:16:46 -0600 (Wed, 25 Nov 2009) | 29 lines
Merged revisions 76160-76161,76250,76252,76447,76506 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r76160 | benjamin.peterson | 2009-11-08 18:53:48 -0600 (Sun, 08 Nov 2009) | 1 line
undeprecate the -p option; it's useful for converting python3 sources
........
r76161 | benjamin.peterson | 2009-11-08 19:05:37 -0600 (Sun, 08 Nov 2009) | 1 line
simplify condition
........
r76250 | benjamin.peterson | 2009-11-13 16:56:48 -0600 (Fri, 13 Nov 2009) | 1 line
fix handling of a utf-8 bom #7313
........
r76252 | benjamin.peterson | 2009-11-13 16:58:36 -0600 (Fri, 13 Nov 2009) | 1 line
remove pdb turd
........
r76447 | benjamin.peterson | 2009-11-22 18:17:40 -0600 (Sun, 22 Nov 2009) | 1 line
#7375 fix nested transformations in fix_urllib
........
r76506 | benjamin.peterson | 2009-11-24 18:34:31 -0600 (Tue, 24 Nov 2009) | 1 line
use generator expressions in any()
........
................
2009-11-25 14:34:42 -04:00
|
|
|
.. method:: formatyear(theyear, w=2, l=1, c=6, m=3)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return a *m*-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 specified in the constructor or set by the
|
|
|
|
:meth:`setfirstweekday` method. The earliest year for which a calendar
|
|
|
|
can be generated is platform-dependent.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. method:: pryear(theyear, w=2, l=1, c=6, m=3)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Print the calendar for an entire year as returned by :meth:`formatyear`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. class:: HTMLCalendar(firstweekday=0)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
This class can be used to generate HTML calendars.
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
:class:`HTMLCalendar` instances have the following methods:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. method:: formatmonth(theyear, themonth, withyear=True)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return a month's calendar as an HTML table. If *withyear* is true the year
|
|
|
|
will be included in the header, otherwise just the month name will be
|
|
|
|
used.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
Merged revisions 76259,76326,76376-76377,76430,76471,76517 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r76259 | georg.brandl | 2009-11-14 05:50:51 -0600 (Sat, 14 Nov 2009) | 1 line
Fix terminology.
................
r76326 | georg.brandl | 2009-11-16 10:44:05 -0600 (Mon, 16 Nov 2009) | 1 line
#7302: fix link.
................
r76376 | georg.brandl | 2009-11-18 13:39:14 -0600 (Wed, 18 Nov 2009) | 1 line
upcase Python
................
r76377 | georg.brandl | 2009-11-18 14:05:15 -0600 (Wed, 18 Nov 2009) | 1 line
Fix markup.
................
r76430 | r.david.murray | 2009-11-20 07:29:43 -0600 (Fri, 20 Nov 2009) | 2 lines
Issue 7363: fix indentation in socketserver udpserver example.
................
r76471 | georg.brandl | 2009-11-23 13:53:19 -0600 (Mon, 23 Nov 2009) | 1 line
#7345: fix arguments of formatyear().
................
r76517 | benjamin.peterson | 2009-11-25 12:16:46 -0600 (Wed, 25 Nov 2009) | 29 lines
Merged revisions 76160-76161,76250,76252,76447,76506 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r76160 | benjamin.peterson | 2009-11-08 18:53:48 -0600 (Sun, 08 Nov 2009) | 1 line
undeprecate the -p option; it's useful for converting python3 sources
........
r76161 | benjamin.peterson | 2009-11-08 19:05:37 -0600 (Sun, 08 Nov 2009) | 1 line
simplify condition
........
r76250 | benjamin.peterson | 2009-11-13 16:56:48 -0600 (Fri, 13 Nov 2009) | 1 line
fix handling of a utf-8 bom #7313
........
r76252 | benjamin.peterson | 2009-11-13 16:58:36 -0600 (Fri, 13 Nov 2009) | 1 line
remove pdb turd
........
r76447 | benjamin.peterson | 2009-11-22 18:17:40 -0600 (Sun, 22 Nov 2009) | 1 line
#7375 fix nested transformations in fix_urllib
........
r76506 | benjamin.peterson | 2009-11-24 18:34:31 -0600 (Tue, 24 Nov 2009) | 1 line
use generator expressions in any()
........
................
2009-11-25 14:34:42 -04:00
|
|
|
.. method:: formatyear(theyear, width=3)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return a year's calendar as an HTML table. *width* (defaulting to 3)
|
|
|
|
specifies the number of months per row.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. method:: formatyearpage(theyear, width=3, css='calendar.css', encoding=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return a year's calendar as a complete HTML page. *width* (defaulting to
|
|
|
|
3) specifies the number of months per row. *css* is the name for the
|
|
|
|
cascading style sheet to be used. :const:`None` can be passed if no style
|
|
|
|
sheet should be used. *encoding* specifies the encoding to be used for the
|
|
|
|
output (defaulting to the system default encoding).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. class:: LocaleTextCalendar(firstweekday=0, locale=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
This subclass of :class:`TextCalendar` can be passed a locale name in the
|
2010-10-19 15:54:25 -03:00
|
|
|
constructor and will return month and weekday names in the specified locale.
|
|
|
|
If this locale includes an encoding all strings containing month and weekday
|
|
|
|
names will be returned as unicode.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. class:: LocaleHTMLCalendar(firstweekday=0, locale=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
This subclass of :class:`HTMLCalendar` can be passed a locale name in the
|
2008-04-24 22:59:09 -03:00
|
|
|
constructor and will return month and weekday names in the specified
|
|
|
|
locale. If this locale includes an encoding all strings containing month and
|
|
|
|
weekday names will be returned as unicode.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-10-19 15:54:25 -03:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
The :meth:`formatweekday` and :meth:`formatmonthname` methods of these two
|
|
|
|
classes temporarily change the current locale to the given *locale*. Because
|
|
|
|
the current locale is a process-wide setting, they are not thread-safe.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
For simple text calendars this module provides the following functions.
|
|
|
|
|
|
|
|
.. function:: setfirstweekday(weekday)
|
|
|
|
|
|
|
|
Sets the weekday (``0`` is Monday, ``6`` is Sunday) to start each week. The
|
|
|
|
values :const:`MONDAY`, :const:`TUESDAY`, :const:`WEDNESDAY`, :const:`THURSDAY`,
|
|
|
|
:const:`FRIDAY`, :const:`SATURDAY`, and :const:`SUNDAY` are provided for
|
|
|
|
convenience. For example, to set the first weekday to Sunday::
|
|
|
|
|
|
|
|
import calendar
|
|
|
|
calendar.setfirstweekday(calendar.SUNDAY)
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: firstweekday()
|
|
|
|
|
|
|
|
Returns the current setting for the weekday to start each week.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: isleap(year)
|
|
|
|
|
|
|
|
Returns :const:`True` if *year* is a leap year, otherwise :const:`False`.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: leapdays(y1, y2)
|
|
|
|
|
|
|
|
Returns the number of leap years in the range from *y1* to *y2* (exclusive),
|
|
|
|
where *y1* and *y2* are years.
|
|
|
|
|
2007-09-01 10:51:09 -03:00
|
|
|
This function works for ranges spanning a century change.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. function:: weekday(year, month, day)
|
|
|
|
|
|
|
|
Returns the day of the week (``0`` is Monday) for *year* (``1970``--...),
|
|
|
|
*month* (``1``--``12``), *day* (``1``--``31``).
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: weekheader(n)
|
|
|
|
|
|
|
|
Return a header containing abbreviated weekday names. *n* specifies the width in
|
|
|
|
characters for one weekday.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: monthrange(year, month)
|
|
|
|
|
|
|
|
Returns weekday of first day of the month and number of days in month, for the
|
|
|
|
specified *year* and *month*.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: 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 :func:`setfirstweekday`.
|
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. function:: prmonth(theyear, themonth, w=0, l=0)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Prints a month's calendar as returned by :func:`month`.
|
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. function:: month(theyear, themonth, w=0, l=0)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Returns a month's calendar in a multi-line string using the :meth:`formatmonth`
|
|
|
|
of the :class:`TextCalendar` class.
|
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. function:: prcal(year, w=0, l=0, c=6, m=3)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Prints the calendar for an entire year as returned by :func:`calendar`.
|
|
|
|
|
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
.. function:: calendar(year, w=2, l=1, c=6, m=3)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-04-05 19:20:44 -03:00
|
|
|
Returns a 3-column calendar for an entire year as a multi-line string using
|
|
|
|
the :meth:`formatyear` of the :class:`TextCalendar` class.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. function:: timegm(tuple)
|
|
|
|
|
|
|
|
An unrelated but handy function that takes a time tuple such as returned by the
|
|
|
|
:func:`gmtime` function in the :mod:`time` module, and returns the corresponding
|
|
|
|
Unix timestamp value, assuming an epoch of 1970, and the POSIX encoding. In
|
|
|
|
fact, :func:`time.gmtime` and :func:`timegm` are each others' inverse.
|
|
|
|
|
|
|
|
|
|
|
|
The :mod:`calendar` module exports the following data attributes:
|
|
|
|
|
|
|
|
.. data:: day_name
|
|
|
|
|
|
|
|
An array that represents the days of the week in the current locale.
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: day_abbr
|
|
|
|
|
|
|
|
An array that represents the abbreviated days of the week in the current locale.
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: month_name
|
|
|
|
|
|
|
|
An array that represents the months of the year in the current locale. This
|
|
|
|
follows normal convention of January being month number 1, so it has a length of
|
|
|
|
13 and ``month_name[0]`` is the empty string.
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: month_abbr
|
|
|
|
|
|
|
|
An array that represents the abbreviated months of the year in the current
|
|
|
|
locale. This follows normal convention of January being month number 1, so it
|
|
|
|
has a length of 13 and ``month_abbr[0]`` is the empty string.
|
|
|
|
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
Module :mod:`datetime`
|
|
|
|
Object-oriented interface to dates and times with similar functionality to the
|
|
|
|
:mod:`time` module.
|
|
|
|
|
|
|
|
Module :mod:`time`
|
|
|
|
Low-level time related functions.
|