(text: str, **options: Any)
| 108 | |
| 109 | |
| 110 | def _parse(text: str, **options: Any) -> datetime | date | time | _Interval | Duration: |
| 111 | # Trying to parse ISO8601 |
| 112 | with contextlib.suppress(ValueError): |
| 113 | return parse_iso8601(text) |
| 114 | |
| 115 | with contextlib.suppress(ValueError): |
| 116 | return _parse_iso8601_interval(text) |
| 117 | |
| 118 | with contextlib.suppress(ParserError): |
| 119 | return _parse_common(text, **options) |
| 120 | |
| 121 | # We couldn't parse the string |
| 122 | # so we fallback on the dateutil parser |
| 123 | # If not strict |
| 124 | if options.get("strict", True): |
| 125 | raise ParserError(f"Unable to parse string [{text}]") |
| 126 | |
| 127 | try: |
| 128 | dt = parser.parse( |
| 129 | text, dayfirst=options["day_first"], yearfirst=options["year_first"] |
| 130 | ) |
| 131 | except ValueError: |
| 132 | raise ParserError(f"Invalid date string: {text}") |
| 133 | |
| 134 | return dt |
| 135 | |
| 136 | |
| 137 | def _parse_common(text: str, **options: Any) -> datetime | date | time: |
no test coverage detected
searching dependent graphs…