A combination of a date and a time. The year, month and day arguments are required. tzinfo may be None, or an instance of a tzinfo subclass. The remaining arguments may be ints.
| 1779 | |
| 1780 | |
| 1781 | class datetime(date): |
| 1782 | """A combination of a date and a time. |
| 1783 | |
| 1784 | The year, month and day arguments are required. tzinfo may be None, or an |
| 1785 | instance of a tzinfo subclass. The remaining arguments may be ints. |
| 1786 | """ |
| 1787 | __slots__ = time.__slots__ |
| 1788 | |
| 1789 | def __new__(cls, year, month=None, day=None, hour=0, minute=0, second=0, |
| 1790 | microsecond=0, tzinfo=None, *, fold=0): |
| 1791 | if (isinstance(year, (bytes, str)) and len(year) == 10 and |
| 1792 | 1 <= ord(year[2:3])&0x7F <= 12): |
| 1793 | # Pickle support |
| 1794 | if isinstance(year, str): |
| 1795 | try: |
| 1796 | year = bytes(year, 'latin1') |
| 1797 | except UnicodeEncodeError: |
| 1798 | # More informative error message. |
| 1799 | raise ValueError( |
| 1800 | "Failed to encode latin1 string when unpickling " |
| 1801 | "a datetime object. " |
| 1802 | "pickle.load(data, encoding='latin1') is assumed.") |
| 1803 | self = object.__new__(cls) |
| 1804 | self.__setstate(year, month) |
| 1805 | self._hashcode = -1 |
| 1806 | return self |
| 1807 | year, month, day = _check_date_fields(year, month, day) |
| 1808 | hour, minute, second, microsecond, fold = _check_time_fields( |
| 1809 | hour, minute, second, microsecond, fold) |
| 1810 | _check_tzinfo_arg(tzinfo) |
| 1811 | self = object.__new__(cls) |
| 1812 | self._year = year |
| 1813 | self._month = month |
| 1814 | self._day = day |
| 1815 | self._hour = hour |
| 1816 | self._minute = minute |
| 1817 | self._second = second |
| 1818 | self._microsecond = microsecond |
| 1819 | self._tzinfo = tzinfo |
| 1820 | self._hashcode = -1 |
| 1821 | self._fold = fold |
| 1822 | return self |
| 1823 | |
| 1824 | # Read-only field accessors |
| 1825 | @property |
| 1826 | def hour(self): |
| 1827 | """hour (0-23)""" |
| 1828 | return self._hour |
| 1829 | |
| 1830 | @property |
| 1831 | def minute(self): |
| 1832 | """minute (0-59)""" |
| 1833 | return self._minute |
| 1834 | |
| 1835 | @property |
| 1836 | def second(self): |
| 1837 | """second (0-59)""" |
| 1838 | return self._second |
no outgoing calls
searching dependent graphs…