MCPcopy Index your code
hub / github.com/python/cpython / iso2time

Function iso2time

Lib/http/cookiejar.py:306–333  ·  view source on GitHub ↗

As for http2time, but parses the ISO 8601 formats: 1994-02-03 14:15:29 -0100 -- ISO 8601 format 1994-02-03 14:15:29 -- zone is optional 1994-02-03 -- only date 1994-02-03T14:15:29 -- Use T as separator 19940203T141529Z -- I

(text)

Source from the content-addressed store, hash-verified

304 \s*
305 )?$""", re.X | re. ASCII)
306def iso2time(text):
307 """
308 As for http2time, but parses the ISO 8601 formats:
309
310 1994-02-03 14:15:29 -0100 -- ISO 8601 format
311 1994-02-03 14:15:29 -- zone is optional
312 1994-02-03 -- only date
313 1994-02-03T14:15:29 -- Use T as separator
314 19940203T141529Z -- ISO 8601 compact format
315 19940203 -- only date
316
317 """
318 # clean up
319 text = text.lstrip()
320
321 # tz is time zone specifier string
322 day, mon, yr, hr, min, sec, tz = [None]*7
323
324 # loose regexp parse
325 m = ISO_DATE_RE.search(text)
326 if m is not None:
327 # XXX there's an extra bit of the timezone I'm ignoring here: is
328 # this the right thing to do?
329 yr, mon, day, hr, min, sec, tz, _ = m.groups()
330 else:
331 return None # bad format
332
333 return _str2time(day, mon, yr, hr, min, sec, tz)
334
335
336# Header parsing

Callers 5

parse_dateMethod · 0.90
test_iso2time_formatsMethod · 0.90
test_iso2time_garbageMethod · 0.90
_really_loadMethod · 0.85

Calls 4

_str2timeFunction · 0.85
lstripMethod · 0.45
searchMethod · 0.45
groupsMethod · 0.45

Tested by 4

parse_dateMethod · 0.72
test_iso2time_formatsMethod · 0.72
test_iso2time_garbageMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…