Construct a time from a string in one of the ISO 8601 formats.
(cls, time_string)
| 1632 | |
| 1633 | @classmethod |
| 1634 | def fromisoformat(cls, time_string): |
| 1635 | """Construct a time from a string in one of the ISO 8601 formats.""" |
| 1636 | if not isinstance(time_string, str): |
| 1637 | raise TypeError('fromisoformat: argument must be str') |
| 1638 | |
| 1639 | # The spec actually requires that time-only ISO 8601 strings start with |
| 1640 | # T, but the extended format allows this to be omitted as long as there |
| 1641 | # is no ambiguity with date strings. |
| 1642 | time_string = time_string.removeprefix('T') |
| 1643 | |
| 1644 | try: |
| 1645 | time_components, _, error_from_components, error_from_tz = ( |
| 1646 | _parse_isoformat_time(time_string) |
| 1647 | ) |
| 1648 | except ValueError: |
| 1649 | raise ValueError( |
| 1650 | f'Invalid isoformat string: {time_string!r}') from None |
| 1651 | else: |
| 1652 | if error_from_tz: |
| 1653 | raise error_from_tz |
| 1654 | if error_from_components: |
| 1655 | raise ValueError( |
| 1656 | "Minute, second, and microsecond must be 0 when hour is 24" |
| 1657 | ) |
| 1658 | |
| 1659 | return cls(*time_components) |
| 1660 | |
| 1661 | def strftime(self, format): |
| 1662 | """Format using strftime(). The date part of the timestamp passed |
nothing calls this directly
no test coverage detected