@@ -872,12 +872,7 @@ def format_is_iso(f: str) -> bint:
872
872
return False
873
873
874
874
875
- def guess_datetime_format (
876
- dt_str ,
877
- bint dayfirst = False ,
878
- dt_str_parse = du_parse,
879
- dt_str_split = _DATEUTIL_LEXER_SPLIT,
880
- ):
875
+ def guess_datetime_format (dt_str , bint dayfirst = False ):
881
876
"""
882
877
Guess the datetime format of a given datetime string.
883
878
@@ -889,20 +884,11 @@ def guess_datetime_format(
889
884
If True parses dates with the day first, eg 20/01/2005
890
885
Warning: dayfirst=True is not strict, but will prefer to parse
891
886
with day first (this is a known bug).
892
- dt_str_parse : function, defaults to `dateutil.parser.parse`
893
- This function should take in a datetime string and return
894
- a `datetime.datetime` guess that the datetime string represents
895
- dt_str_split : function, defaults to `_DATEUTIL_LEXER_SPLIT` (dateutil)
896
- This function should take in a datetime string and return
897
- a list of strings, the guess of the various specific parts
898
- e.g. '2011/12/30' -> ['2011', '/', '12', '/', '30']
899
887
900
888
Returns
901
889
-------
902
890
ret : datetime format string (for `strftime` or `strptime`)
903
891
"""
904
- if dt_str_parse is None or dt_str_split is None :
905
- return None
906
892
907
893
if not isinstance (dt_str, str ):
908
894
return None
@@ -934,17 +920,16 @@ def guess_datetime_format(
934
920
datetime_attrs_to_format.insert(0 , day_attribute_and_format)
935
921
936
922
try :
937
- parsed_datetime = dt_str_parse (dt_str, dayfirst = dayfirst)
923
+ parsed_datetime = du_parse (dt_str, dayfirst = dayfirst)
938
924
except (ValueError , OverflowError ):
939
925
# In case the datetime can't be parsed, its format cannot be guessed
940
926
return None
941
927
942
928
if parsed_datetime is None :
943
929
return None
944
930
945
- # the default dt_str_split from dateutil will never raise here; we assume
946
- # that any user-provided function will not either.
947
- tokens = dt_str_split(dt_str)
931
+ # _DATEUTIL_LEXER_SPLIT from dateutil will never raise here
932
+ tokens = _DATEUTIL_LEXER_SPLIT(dt_str)
948
933
949
934
# Normalize offset part of tokens.
950
935
# There are multiple formats for the timezone offset.
0 commit comments