{"record":{"id":"96d84dedd8ab126e","repo":"TheAlgorithms/Python","slug":"date-separator-must-be-or","errorCode":null,"errorMessage":"Date separator must be '-' or '/'","messagePattern":"Date separator must be '-' or '/'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/zellers_congruence.py","lineNumber":100,"sourceCode":"        \"6\": \"Saturday\",\n    }\n\n    convert_datetime_days = {0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 0}\n\n    # Validate\n    if not 0 < len(date_input) < 11:\n        raise ValueError(\"Must be 10 characters long\")\n\n    # Get month\n    m: int = int(date_input[0] + date_input[1])\n    # Validate\n    if not 0 < m < 13:\n        raise ValueError(\"Month must be between 1 - 12\")\n\n    sep_1: str = date_input[2]\n    # Validate\n    if sep_1 not in [\"-\", \"/\"]:\n        raise ValueError(\"Date separator must be '-' or '/'\")\n\n    # Get day\n    d: int = int(date_input[3] + date_input[4])\n    # Validate\n    if not 0 < d < 32:\n        raise ValueError(\"Date must be between 1 - 31\")\n\n    # Get second separator\n    sep_2: str = date_input[5]\n    # Validate\n    if sep_2 not in [\"-\", \"/\"]:\n        raise ValueError(\"Date separator must be '-' or '/'\")\n\n    # Get year\n    y: int = int(date_input[6] + date_input[7] + date_input[8] + date_input[9])\n    # Arbitrary year range\n    if not 45 < y < 8500:\n        raise ValueError(","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/zellers_congruence.py#L82-L118","documentation":"Raised by zeller(date_input) in maths/zellers_congruence.py when the character at position 2 (the separator between month and day) is not '-' or '/'. The parser is strictly positional: chars 2 and 5 must be separators, digits are taken from fixed offsets. This is the first-separator check, hit by inputs like '01^31-2010'.","triggerScenarios":"Calling zeller('01.31.2010'), zeller('01 31 2010') or zeller('01^31-2010'); dates produced with '.', ' ' or other separators; strings where a leading character shifted positions.","commonSituations":"Locale-specific separators (dots in European dates, dots/spaces in ISO-adjacent formats); copy-pasted dates with non-breaking spaces; downstream systems reformatting the string.","solutions":["Reformat the date with '-' separators before calling: s.replace('.', '-').replace('/', '-') after verifying overall shape.","Best: rebuild the string from a parsed date via strftime('%m-%d-%Y') so separators are guaranteed correct.","Pre-validate with a regex such as ^\\d{2}[-/]\\d{2}[-/]\\d{4}$ and reject mismatches early."],"exampleFix":"# before\nzeller('01.31.2010')  # '.' separator -> ValueError\n\n# after\nzeller('01.31.2010'.replace('.', '-'))  # '01-31-2010'","handlingStrategy":"validation","validationCode":"import re\n\ndef has_valid_separators(s: str) -> bool:\n    return len(s) == 10 and s[2] in '-/' and s[5] in '-/'\n\nnormalized = re.sub(r'[.\\s]+', '-', s)","typeGuard":null,"tryCatchPattern":"try:\n    day = zeller(s)\nexcept ValueError as e:\n    if 'separator' in str(e):\n        day = zeller(re.sub(r'[. ]', '-', s))\n    else:\n        raise","preventionTips":["Only '-' and '/' are accepted at positions 2 and 5.","Normalize locale separators before calling."],"tags":["date","validation","string-parsing","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}