Skip to content
Snippets Groups Projects
Commit 5c7fa43e authored by Anton Sarukhanov's avatar Anton Sarukhanov
Browse files

Avoid duplicate no-leading-zero variants.

parent e55d3983
No related branches found
No related tags found
No related merge requests found
Pipeline #112 passed with stage
in 38 seconds
...@@ -23,6 +23,7 @@ def get_all_format_strings(date_string, allow_reuse=False, ...@@ -23,6 +23,7 @@ def get_all_format_strings(date_string, allow_reuse=False,
parsed_datetime = parse(date_string) parsed_datetime = parse(date_string)
except ParserError: except ParserError:
yield '' yield ''
return
tokens = DATE_TOKEN_REGEX.findall(date_string) tokens = DATE_TOKEN_REGEX.findall(date_string)
possible_matches = defaultdict(list) # type: Dict[str, List[str]] possible_matches = defaultdict(list) # type: Dict[str, List[str]]
for test_format in FORMAT_DIRECTIVES: for test_format in FORMAT_DIRECTIVES:
...@@ -39,9 +40,9 @@ def get_all_format_strings(date_string, allow_reuse=False, ...@@ -39,9 +40,9 @@ def get_all_format_strings(date_string, allow_reuse=False,
possible_combinations = list(product(*possible_parts)) possible_combinations = list(product(*possible_parts))
for parts_sequence in possible_combinations: for parts_sequence in possible_combinations:
if not no_zero and any(['%-' in x for x in parts_sequence]): if any([bool('%-' in x) for x in parts_sequence]) and not no_zero:
without_zero = [x.replace('%-', '%') for x in parts_sequence] if str(parts_sequence).replace('%-', '%') in \
if without_zero in possible_combinations: [str(c) for c in possible_combinations]:
continue continue
if not allow_reuse: if not allow_reuse:
counts = Counter(parts_sequence) counts = Counter(parts_sequence)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment