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

Function parse_iso8601

src/pendulum/parsing/iso8601.py:85–263  ·  view source on GitHub ↗

ISO 8601 compliant parser. :param text: The string to parse :type text: str :rtype: datetime.datetime or datetime.time or datetime.date

(
    text: str,
)

Source from the content-addressed store, hash-verified

83
84
85def parse_iso8601(
86 text: str,
87) -> datetime.datetime | datetime.date | datetime.time | Duration:
88 """
89 ISO 8601 compliant parser.
90
91 :param text: The string to parse
92 :type text: str
93
94 :rtype: datetime.datetime or datetime.time or datetime.date
95 """
96 parsed = _parse_iso8601_duration(text)
97 if parsed is not None:
98 return parsed
99
100 m = ISO8601_DT.fullmatch(text)
101 if not m:
102 raise ParserError("Invalid ISO 8601 string")
103
104 ambiguous_date = False
105 is_date = False
106 is_time = False
107 year = 0
108 month = 1
109 day = 1
110 minute = 0
111 second = 0
112 microsecond = 0
113 tzinfo: FixedTimezone | Timezone | None = None
114
115 if m.group("date"):
116 # A date has been specified
117 is_date = True
118
119 if m.group("isocalendar"):
120 # We have a ISO 8601 string defined
121 # by week number
122 if (
123 m.group("weeksep")
124 and not m.group("weekdaysep")
125 and m.group("isoweekday")
126 ):
127 raise ParserError(f"Invalid date string: {text}")
128
129 if not m.group("weeksep") and m.group("weekdaysep"):
130 raise ParserError(f"Invalid date string: {text}")
131
132 try:
133 date = _get_iso_8601_week(
134 m.group("isoyear"), m.group("isoweek"), m.group("isoweekday")
135 )
136 except ParserError:
137 raise
138 except ValueError:
139 raise ParserError(f"Invalid date string: {text}")
140
141 year = date["year"]
142 month = date["month"]

Callers 7

_parseFunction · 0.90
_parse_iso8601_intervalFunction · 0.90
test_parse_iso8601Function · 0.90
test_parse_iso8601Function · 0.90

Calls 8

ParserErrorClass · 0.90
is_leapFunction · 0.90
FixedTimezoneClass · 0.90
_parse_iso8601_durationFunction · 0.85
_get_iso_8601_weekFunction · 0.85
timeMethod · 0.80
dateMethod · 0.80
datetimeMethod · 0.45

Tested by 5

test_parse_iso8601Function · 0.72
test_parse_iso8601Function · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…