diff --git a/whatformat/util/whatdateformat.py b/whatformat/util/whatdateformat.py index 51022efb1af0441e0af322df483db98bcaba7ec7..41859f3dc4578ee6b4aeeacf424365146229eeae 100644 --- a/whatformat/util/whatdateformat.py +++ b/whatformat/util/whatdateformat.py @@ -23,6 +23,7 @@ def get_all_format_strings(date_string, allow_reuse=False, parsed_datetime = parse(date_string) except ParserError: yield '' + return tokens = DATE_TOKEN_REGEX.findall(date_string) possible_matches = defaultdict(list) # type: Dict[str, List[str]] for test_format in FORMAT_DIRECTIVES: @@ -39,9 +40,9 @@ def get_all_format_strings(date_string, allow_reuse=False, possible_combinations = list(product(*possible_parts)) for parts_sequence in possible_combinations: - if not no_zero and any(['%-' in x for x in parts_sequence]): - without_zero = [x.replace('%-', '%') for x in parts_sequence] - if without_zero in possible_combinations: + if any([bool('%-' in x) for x in parts_sequence]) and not no_zero: + if str(parts_sequence).replace('%-', '%') in \ + [str(c) for c in possible_combinations]: continue if not allow_reuse: counts = Counter(parts_sequence)