{"record":{"id":"ee30e152717cedeb","repo":"TheAlgorithms/Java","slug":"date-separator-must-be-or","errorCode":null,"errorMessage":"Date separator must be '-' or '/'.","messagePattern":"Date separator must be '-' or '/'\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/ZellersCongruence.java","lineNumber":104,"sourceCode":"            int value = Integer.parseInt(part);\n            if (value < min || value > max) {\n                throw new IllegalArgumentException(error);\n            }\n            return value;\n        } catch (NumberFormatException e) {\n            throw new IllegalArgumentException(\"Invalid numeric part: \" + part, e);\n        }\n    }\n\n    /**\n     * Validates the separator character in the date string.\n     *\n     * @param sep the separator character\n     * @throws IllegalArgumentException if the separator is not '-' or '/'\n     */\n    private static void validateSeparator(char sep) {\n        if (sep != '-' && sep != '/') {\n            throw new IllegalArgumentException(\"Date separator must be '-' or '/'.\");\n        }\n    }\n}\n","sourceCodeStart":86,"sourceCodeEnd":108,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/ZellersCongruence.java#L86-L108","documentation":"Thrown by ZellersCongruence.validateSeparator when the character at position 2 or 5 of the input is neither '-' nor '/'. The util accepts exactly two separator styles (MM-DD-YYYY or MM/DD/YYYY); any other delimiter ( '.', ' ', '\\', ',') is rejected. Both separators in a single string may even differ and still pass, as long as each is one of the two allowed chars.","triggerScenarios":"Call calculateDay(\"01.01.2020\"), calculateDay(\"01 01 2020\"), calculateDay(\"01\\01\\2020\"), or any input using a delimiter other than '-' or '/'.","commonSituations":"Locale-specific formats (ISO with '-', European with '.', US with '/'), data exported from Excel/spreadsheets using '.', or copy-paste from systems using a different delimiter.","solutions":["Normalize separators to '-' (or '/') before calling: input.replace('.', '-').replace('/', '-').","Validate the delimiter at the input layer and reject/convert early.","Standardize on a single canonical format upstream of this util."],"exampleFix":"// before\nString day = ZellersCongruence.calculateDay(raw);\n\n// after\nString normalized = raw.replace('.', '-').replace(' ', '-').replace('\\\\', '/');\nString day = ZellersCongruence.calculateDay(normalized);","handlingStrategy":"validation","validationCode":"String normalized = input.replaceAll(\"[. \\\\\\\\]\", \"-\").replace('/', '-');\nString d = ZellersCongruence.calculateDay(normalized);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize all delimiters to a single canonical character before calling.","Standardize on one date format across your ingestion pipeline."],"tags":["date","zellers-congruence","format-validation","delimiter"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}