{"record":{"id":"244bed423d4ffa8a","repo":"TheAlgorithms/Python","slug":"must-be-10-characters-long","errorCode":null,"errorMessage":"Must be 10 characters long","messagePattern":"Must be 10 characters long","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/zellers_congruence.py","lineNumber":89,"sourceCode":"        ...\n    ValueError: Must be 10 characters long\"\"\"\n\n    # Days of the week for response\n    days = {\n        \"0\": \"Sunday\",\n        \"1\": \"Monday\",\n        \"2\": \"Tuesday\",\n        \"3\": \"Wednesday\",\n        \"4\": \"Thursday\",\n        \"5\": \"Friday\",\n        \"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","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/zellers_congruence.py#L71-L107","documentation":"Raised by zeller(date_input) in maths/zellers_congruence.py when the input string is not within 1..10 characters, i.e. not the expected 10-character MM-DD-YYYY or MM/DD/YYYY shape. It is the first validation in the function, so it fires before month/day/separator checks. The message says 'Must be 10 characters long' although the code actually accepts any length from 1 to 10 due to the 0 < len < 11 condition.","triggerScenarios":"Calling zeller('') (empty string) or zeller('01-31-19082939') (over-long year); passing ISO dates like '2010-01-31' or datetime objects/None, which hit this or a later type error before any parsing succeeds.","commonSituations":"Feeding ISO-format dates (YYYY-MM-DD) into a function expecting MM-DD-YYYY; passing user input without normalizing; passing a date object instead of its string representation.","solutions":["Normalize your date to the 'MM-DD-YYYY' string format (e.g. dt.strftime('%m-%d-%Y')) before calling zeller.","If input can vary, pre-validate with a regex or strptime('mm-dd-yyyy') and reject early.","Trim accidental whitespace/newlines from read lines before passing them in."],"exampleFix":"# before\nzeller('2010-01-31')  # wrong order + wrong shape\n\n# after\nimport datetime\nzeller(datetime.date(2010, 1, 31).strftime('%m-%d-%Y'))  # '01-31-2010'","handlingStrategy":"validation","validationCode":"import re\nZELLER_RE = re.compile(r'^\\d{2}[-/]\\d{2}[-/]\\d{4}$')\n\ndef is_zeller_date(s: str) -> bool:\n    return isinstance(s, str) and bool(ZELLER_RE.match(s))","typeGuard":"def is_zeller_date(s: str) -> TypeGuard[str]:\n    return isinstance(s, str) and len(s) == 10 and bool(ZELLER_RE.match(s))","tryCatchPattern":"try:\n    day = zeller(date_str)\nexcept ValueError as e:\n    # covers length, month, day, separator, year errors\n    return f'unrecognized date {date_str!r}: {e}'","preventionTips":["zeller expects MM-DD-YYYY or MM/DD/YYYY only — not ISO.","Produce the string via strftime('%m-%d-%Y') instead of hand-building it."],"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"}