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

Function _parse_isoformat_date

Lib/_pydatetime.py:358–391  ·  view source on GitHub ↗
(dtstr)

Source from the content-addressed store, hash-verified

356
357
358def _parse_isoformat_date(dtstr):
359 # It is assumed that this is an ASCII-only string of lengths 7, 8 or 10,
360 # see the comment on Modules/_datetimemodule.c:_find_isoformat_datetime_separator
361 assert len(dtstr) in (7, 8, 10)
362 year = int(dtstr[0:4])
363 has_sep = dtstr[4] == '-'
364
365 pos = 4 + has_sep
366 if dtstr[pos:pos + 1] == "W":
367 # YYYY-?Www-?D?
368 pos += 1
369 weekno = int(dtstr[pos:pos + 2])
370 pos += 2
371
372 dayno = 1
373 if len(dtstr) > pos:
374 if (dtstr[pos:pos + 1] == '-') != has_sep:
375 raise ValueError("Inconsistent use of dash separator")
376
377 pos += has_sep
378
379 dayno = int(dtstr[pos:pos + 1])
380
381 return list(_isoweek_to_gregorian(year, weekno, dayno))
382 else:
383 month = int(dtstr[pos:pos + 2])
384 pos += 2
385 if (dtstr[pos:pos + 1] == "-") != has_sep:
386 raise ValueError("Inconsistent use of dash separator")
387
388 pos += has_sep
389 day = int(dtstr[pos:pos + 2])
390
391 return [year, month, day]
392
393
394_FRACTION_CORRECTION = [100000, 10000, 1000, 100, 10]

Callers 2

fromisoformatMethod · 0.85
fromisoformatMethod · 0.85

Calls 2

listClass · 0.85
_isoweek_to_gregorianFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…