Construct a datetime from a string in one of the ISO 8601 formats.
(cls, date_string)
| 1821 | |
| 1822 | @classmethod |
| 1823 | def fromisoformat(cls, date_string): |
| 1824 | """Construct a datetime from a string in one of the ISO 8601 formats.""" |
| 1825 | if not isinstance(date_string, str): |
| 1826 | raise TypeError('fromisoformat: argument must be str') |
| 1827 | |
| 1828 | if len(date_string) < 7: |
| 1829 | raise ValueError(f'Invalid isoformat string: {date_string!r}') |
| 1830 | |
| 1831 | # Split this at the separator |
| 1832 | try: |
| 1833 | separator_location = _find_isoformat_datetime_separator(date_string) |
| 1834 | dstr = date_string[0:separator_location] |
| 1835 | tstr = date_string[(separator_location+1):] |
| 1836 | |
| 1837 | date_components = _parse_isoformat_date(dstr) |
| 1838 | except ValueError: |
| 1839 | raise ValueError( |
| 1840 | f'Invalid isoformat string: {date_string!r}') from None |
| 1841 | |
| 1842 | if tstr: |
| 1843 | try: |
| 1844 | time_components = _parse_isoformat_time(tstr) |
| 1845 | except ValueError: |
| 1846 | raise ValueError( |
| 1847 | f'Invalid isoformat string: {date_string!r}') from None |
| 1848 | else: |
| 1849 | time_components = [0, 0, 0, 0, None] |
| 1850 | |
| 1851 | return cls(*(date_components + time_components)) |
| 1852 | |
| 1853 | def timetuple(self): |
| 1854 | "Return local time tuple compatible with time.localtime()." |
nothing calls this directly
no test coverage detected