MCPcopy Create free account
hub / github.com/ColdGrub1384/Pyto / _parse_numeric_token

Method _parse_numeric_token

site-packages/dateutil/parser/_parser.py:877–1006  ·  view source on GitHub ↗
(self, tokens, idx, info, ymd, res, fuzzy)

Source from the content-addressed store, hash-verified

875 return res, None
876
877 def _parse_numeric_token(self, tokens, idx, info, ymd, res, fuzzy):
878 # Token is a number
879 value_repr = tokens[idx]
880 try:
881 value = self._to_decimal(value_repr)
882 except Exception as e:
883 six.raise_from(ValueError('Unknown numeric token'), e)
884
885 len_li = len(value_repr)
886
887 len_l = len(tokens)
888
889 if (len(ymd) == 3 and len_li in (2, 4) and
890 res.hour is None and
891 (idx + 1 >= len_l or
892 (tokens[idx + 1] != ':' and
893 info.hms(tokens[idx + 1]) is None))):
894 # 19990101T23[59]
895 s = tokens[idx]
896 res.hour = int(s[:2])
897
898 if len_li == 4:
899 res.minute = int(s[2:])
900
901 elif len_li == 6 or (len_li > 6 and tokens[idx].find('.') == 6):
902 # YYMMDD or HHMMSS[.ss]
903 s = tokens[idx]
904
905 if not ymd and '.' not in tokens[idx]:
906 ymd.append(s[:2])
907 ymd.append(s[2:4])
908 ymd.append(s[4:])
909 else:
910 # 19990101T235959[.59]
911
912 # TODO: Check if res attributes already set.
913 res.hour = int(s[:2])
914 res.minute = int(s[2:4])
915 res.second, res.microsecond = self._parsems(s[4:])
916
917 elif len_li in (8, 12, 14):
918 # YYYYMMDD
919 s = tokens[idx]
920 ymd.append(s[:4], 'Y')
921 ymd.append(s[4:6])
922 ymd.append(s[6:8])
923
924 if len_li > 8:
925 res.hour = int(s[8:10])
926 res.minute = int(s[10:12])
927
928 if len_li > 12:
929 res.second = int(s[12:])
930
931 elif self._find_hms_idx(idx, tokens, info, allow_jump=True) is not None:
932 # HH[ ]h or MM[ ]m or SS[.ss][ ]s
933 hms_idx = self._find_hms_idx(idx, tokens, info, allow_jump=True)
934 (idx, hms) = self._parse_hms(idx, tokens, info, hms_idx)

Callers 1

_parseMethod · 0.95

Calls 15

_to_decimalMethod · 0.95
_parsemsMethod · 0.95
_find_hms_idxMethod · 0.95
_parse_hmsMethod · 0.95
_assign_hmsMethod · 0.95
_parse_min_secMethod · 0.95
_adjust_ampmMethod · 0.95
hmsMethod · 0.80
jumpMethod · 0.80
isdigitMethod · 0.80
monthMethod · 0.80
ampmMethod · 0.80

Tested by

no test coverage detected