{"record":{"id":"14fbc8b8e44ba599","repo":"TheAlgorithms/Java","slug":"year-must-be-between-46-and-8499","errorCode":null,"errorMessage":"Year must be between 46 and 8499.","messagePattern":"Year must be between 46 and 8499\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/ZellersCongruence.java","lineNumber":88,"sourceCode":"\n        return \"The date \" + input + \" falls on a \" + DAYS[correctedDay] + \".\";\n    }\n\n    /**\n     * Parses a part of the date string and validates its range.\n     *\n     * @param part  the substring to parse\n     * @param min   the minimum valid value\n     * @param max   the maximum valid value\n     * @param error the error message to throw if validation fails\n     * @return the parsed integer value\n     * @throws IllegalArgumentException if the part is not a valid number or is out of range\n     */\n    private static int parsePart(String part, int min, int max, String error) {\n        try {\n            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    }","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/ZellersCongruence.java#L70-L106","documentation":"Thrown by ZellersCongruence.parsePart (called for the year substring, positions 6-10) when the parsed year is < 46 or > 8499. This range is the algorithmic validity window for Zeller's congruence as implemented here (the constants/rounding in the formula are tuned for that span); years outside it would yield incorrect weekday results, so they are rejected rather than returning wrong answers.","triggerScenarios":"Call calculateDay(\"01-01-0001\"), calculateDay(\"01-01-9000\"), or any 4-digit year field outside [46, 8499].","commonSituations":"Two-digit years expanded incorrectly (e.g., '22' -> 22 instead of 2022), ancient-history or far-future dates, or test fixtures with year 1.","solutions":["Constrain the year to [46, 8499] at the call site and surface the limit to users.","For 2-digit year input, apply a pivot (e.g., +2000) before formatting.","If you need dates outside the window, use java.time LocalDate directly instead of this util."],"exampleFix":"// before\nString input = String.format(\"%02d-%02d-%04d\", m, d, twoDigitYear);\n\n// after\nint fullYear = twoDigitYear + 2000; // or your pivot\nString input = String.format(\"%02d-%02d-%04d\", m, d, fullYear);","handlingStrategy":"validation","validationCode":"if (year < 46 || year > 8499) throw new IllegalArgumentException(\"year out of [46,8499]\");\nString input = String.format(\"%02d-%02d-%04d\", month, day, year);\nString d = ZellersCongruence.calculateDay(input);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Apply a century pivot to 2-digit years before formatting.","Document the algorithm's [46,8499] validity window to users who may input ancient or far-future dates."],"tags":["date","zellers-congruence","range-validation","argument-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}