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

Function _parse_hh_mm_ss_ff

Lib/_pydatetime.py:397–442  ·  view source on GitHub ↗
(tstr)

Source from the content-addressed store, hash-verified

395
396
397def _parse_hh_mm_ss_ff(tstr):
398 # Parses things of the form HH[:?MM[:?SS[{.,}fff[fff]]]]
399 len_str = len(tstr)
400
401 time_comps = [0, 0, 0, 0]
402 pos = 0
403 for comp in range(0, 3):
404 if (len_str - pos) < 2:
405 raise ValueError("Incomplete time component")
406
407 time_comps[comp] = int(tstr[pos:pos+2])
408
409 pos += 2
410 next_char = tstr[pos:pos+1]
411
412 if comp == 0:
413 has_sep = next_char == ':'
414
415 if not next_char or comp >= 2:
416 break
417
418 if has_sep and next_char != ':':
419 raise ValueError("Invalid time separator: %c" % next_char)
420
421 pos += has_sep
422
423 if pos < len_str:
424 if tstr[pos] not in '.,':
425 raise ValueError("Invalid microsecond separator")
426 else:
427 pos += 1
428 if not all(map(_is_ascii_digit, tstr[pos:])):
429 raise ValueError("Non-digit values in fraction")
430
431 len_remainder = len_str - pos
432
433 if len_remainder >= 6:
434 to_parse = 6
435 else:
436 to_parse = len_remainder
437
438 time_comps[3] = int(tstr[pos:(pos+to_parse)])
439 if to_parse < 6:
440 time_comps[3] *= _FRACTION_CORRECTION[to_parse-1]
441
442 return time_comps
443
444def _parse_isoformat_time(tstr):
445 # Format supported is HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]

Callers 1

_parse_isoformat_timeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…