MCPcopy Index your code
hub / github.com/python/cpython / datetime

Class datetime

Lib/_pydatetime.py:1781–2425  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

1779
1780
1781class 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

Callers 15

Time2InternaldateFunction · 0.90
datetimetester.pyFile · 0.90
test_issue23600Method · 0.90
setUpMethod · 0.90
test_aware_datetimeMethod · 0.90
test_strptime_ampmMethod · 0.90
test_zonesMethod · 0.90
test_combineMethod · 0.90
test_mixed_compareMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_issue23600Method · 0.72
setUpMethod · 0.72
test_aware_datetimeMethod · 0.72
test_strptime_ampmMethod · 0.72
test_zonesMethod · 0.72
test_combineMethod · 0.72
test_mixed_compareMethod · 0.72
_utc_foldMethod · 0.72
_loc_foldMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…