MCPcopy Index your code
hub / github.com/python-pendulum/pendulum / _parse

Function _parse

src/pendulum/parsing/__init__.py:110–134  ·  view source on GitHub ↗
(text: str, **options: Any)

Source from the content-addressed store, hash-verified

108
109
110def _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
137def _parse_common(text: str, **options: Any) -> datetime | date | time:

Callers 1

parseFunction · 0.70

Calls 6

parse_iso8601Function · 0.90
ParserErrorClass · 0.90
_parse_iso8601_intervalFunction · 0.85
_parse_commonFunction · 0.85
getMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…