|
4 | 4 | class date -- Represent a date |
5 | 5 | =============================== |
6 | 6 |
|
| 7 | +A representation of a date, according to the Gregorian calendar. |
| 8 | + |
7 | 9 | :py:class:`~datetime.date` objects support equality and comparison operators. |
8 | 10 |
|
9 | 11 | .. class:: date(year, month, day) |
10 | 12 |
|
11 | | - All arguments are required. Arguments must be integers, in the following ranges: |
| 13 | + Construct a date object representing the given ``year``, ``month`` and ``day``. |
12 | 14 |
|
13 | | - - :py:class:`~datetime.MINYEAR` <= year <= :py:class:`~datetime.MAXYEAR` |
14 | | - - 1 <= month <= 12 |
15 | | - - 1 <= day <= number of days in the given month and year |
| 15 | + Arguments must be integers in the following ranges: |
16 | 16 |
|
17 | | - Other constructors: |
| 17 | + - :py:class:`~datetime.MINYEAR` <= ``year`` <= :py:class:`~datetime.MAXYEAR` |
| 18 | + - ``1`` <= ``month`` <= ``12`` |
| 19 | + - ``1`` <= ``day`` <= number of days in the given month and year |
18 | 20 |
|
19 | 21 | .. classmethod:: today() |
20 | 22 |
|
| 23 | + Construct a date object representing today's year, month and day. |
| 24 | + |
21 | 25 | .. classmethod:: fromtimestamp(timestamp) |
22 | 26 |
|
| 27 | + Construct a date object representing the year, month and day specified by the |
| 28 | + provided ``timestamp``. |
| 29 | + |
| 30 | + A ``timestamp`` in this case is a floating point number representing the |
| 31 | + number of seconds since the epoch (January 1, 1970, 00:00:00 UTC). |
| 32 | + |
23 | 33 | .. classmethod:: fromordinal(ordinal) |
24 | 34 |
|
25 | | - .. classmethod:: fromisoformate(date_string) |
| 35 | + Construct a date object representing the year, month and day specified by the |
| 36 | + provided ``ordinal``. |
| 37 | + |
| 38 | + An ``ordinal`` is an integer representing the number of days since January |
| 39 | + 1st of year 1. |
| 40 | + |
| 41 | + .. classmethod:: fromisoformat(date_string) |
| 42 | + |
| 43 | + Construct a date object from a string in |
| 44 | + `ISO 8601 format <https://www.iso.org/iso-8601-date-and-time-format.html>`_:: |
| 45 | + |
| 46 | + from datetime import date |
| 47 | + d = date.fromisoformat('2012-12-21') |
26 | 48 |
|
27 | | - Class attributes: |
28 | | - |
29 | 49 | .. attribute:: min |
30 | 50 |
|
31 | | - The earliest representable date, date(:py:attr:`~datetime.MINYEAR`, 1, 1). |
| 51 | + The earliest representable date, ``date(datetime.MINYEAR, 1, 1)``. |
32 | 52 |
|
33 | 53 | .. attribute:: max |
34 | 54 |
|
35 | | - The latest representable date, date(:py:attr:`~datetime.MAXYEAR`, 12, 31). |
| 55 | + The latest representable date, ``date(datetime.MAXYEAR, 12, 31)``. |
36 | 56 |
|
37 | 57 | .. attribute:: resolution |
38 | 58 |
|
39 | | - The smallest possible difference between non-equal date objects, ``timedelta(days=1)`` . |
40 | | - |
41 | | - Instance attributes: |
| 59 | + The smallest possible difference between non-equal date objects, |
| 60 | + ``timedelta(days=1)``. |
42 | 61 |
|
43 | 62 | .. attribute:: year |
44 | 63 |
|
| 64 | + The year of the date, an integer in the range :py:class:`~datetime.MINYEAR` |
| 65 | + to :py:class:`~datetime.MAXYEAR`. |
| 66 | + |
45 | 67 | .. attribute:: month |
46 | 68 |
|
| 69 | + The month of the date, an integer in the range ``1`` to ``12``. |
| 70 | + |
47 | 71 | .. attribute:: day |
48 | 72 |
|
49 | | - Instance methods |
| 73 | + The day of the date, an integer in the range ``1`` to the number of days |
| 74 | + in the month represented by :py:attr:`month`. |
50 | 75 |
|
51 | 76 | .. method:: replace(year = self.year, month = self.month, day = self.day) |
52 | 77 |
|
53 | | - Return a new :py:class:`~datetime.date` object with the same values but the specified parameters updated. |
| 78 | + Return a new :py:class:`~datetime.date` object with the same values as the |
| 79 | + existing date object, but with the specified parameters updated. |
54 | 80 |
|
55 | 81 | .. method:: tuple() |
56 | 82 |
|
57 | | - Return the date as a tuple (year, month, day) |
| 83 | + Return the date as a 3-tuple ``(year, month, day)``. |
58 | 84 |
|
59 | 85 | .. method:: timetuple() |
60 | 86 |
|
61 | 87 | Return the date as a 9-tuple |
| 88 | + ``(year, month, day, hour, minute, second, weekday, yearday, dst)``, as |
| 89 | + described in :py:meth:`datetime.datetime.timetuple`. |
| 90 | + |
| 91 | + In this case: |
| 92 | + |
| 93 | + * ``hour``, ``minute`` and ``second`` are all ``0``, as the date object does |
| 94 | + not contain time information. |
| 95 | + * ``weekday`` is the day of the week as an integer, where Monday is ``0`` and |
| 96 | + Sunday is ``6``. |
| 97 | + * ``yearday`` is the day of the year as an integer, where January 1st is |
| 98 | + ``1``. |
| 99 | + * ``dst`` is ``-1``, as the date object does not contain daylight savings |
| 100 | + information. |
62 | 101 |
|
63 | 102 | .. method:: toordinal() |
64 | | - |
65 | | - Return an integer representing the ordinal of the date, where January 1st of year 1 has ordinal 1. |
| 103 | + |
| 104 | + Return an integer representing the ordinal of the date, where January 1st |
| 105 | + of year 1 has ordinal ``1``. |
66 | 106 |
|
67 | 107 | .. method:: isoformat() |
68 | 108 |
|
69 | | - Return a string representing the date in ISO 8601 format, YYYY-MM-DD:: |
| 109 | + Return a string representing the date in |
| 110 | + `ISO 8601 format <https://www.iso.org/iso-8601-date-and-time-format.html>`_, |
| 111 | + ``YYYY-MM-DD``:: |
70 | 112 |
|
71 | 113 | from datetime import date |
72 | 114 | date(2002, 12, 4).isoformat() |
73 | 115 | # outputs '2002-12-04' |
74 | 116 |
|
75 | 117 | .. method:: isoweekday() |
76 | 118 |
|
77 | | - Return the day of the week as an integer, where Monday is 1 and Sunday is 7. |
| 119 | + Return the day of the week as an integer, where Monday is ``1`` and Sunday is |
| 120 | + ``7``. |
78 | 121 |
|
79 | 122 | .. method:: weekday() |
80 | 123 |
|
81 | | - Return the day of the week as an integer, where Monday is 0 and Sunday is 6. |
| 124 | + Return the day of the week as an integer, where Monday is ``0`` and Sunday is |
| 125 | + ``6``. |
0 commit comments