{"record":{"id":"493da3683c8b63f0","repo":"apache/incubator-seata","slug":"the-time-format-does-not-match-yyyy-mm-dd","errorCode":null,"errorMessage":"The time format does not match yyyy-MM-dd","messagePattern":"The time format does not match yyyy-MM-dd","errorType":"validation","errorClass":"DateTimeException","httpStatus":null,"severity":"error","filePath":"console/src/main/java/org/apache/seata/mcp/core/utils/DateUtils.java","lineNumber":41,"sourceCode":"import java.time.ZoneId;\nimport java.time.ZonedDateTime;\nimport java.time.format.DateTimeFormatter;\nimport java.time.format.DateTimeParseException;\nimport java.util.regex.Pattern;\n\npublic class DateUtils {\n\n    public static final Long ONE_DAY_TIMESTAMP = 86400000L;\n\n    private static final Pattern DATE_PATTERN = Pattern.compile(\"^\\\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$\");\n\n    public static boolean isValidDate(String dateStr) {\n        return DATE_PATTERN.matcher(dateStr).matches();\n    }\n\n    public static long convertToTimestampFromDate(String dateStr) {\n        if (!isValidDate(dateStr)) {\n            throw new DateTimeException(\"The time format does not match yyyy-MM-dd\");\n        }\n        LocalDate date = LocalDate.parse(dateStr);\n        ZonedDateTime zonedDateTime = date.atStartOfDay(ZoneId.systemDefault());\n        return zonedDateTime.toInstant().toEpochMilli();\n    }\n\n    public static long convertToTimeStampFromDateTime(String dateTimeStr) {\n        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(\"yyyy-MM-dd HH:mm:ss\");\n\n        try {\n            LocalDateTime dateTime = LocalDateTime.parse(dateTimeStr, formatter);\n            return dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();\n        } catch (DateTimeParseException e) {\n            throw new DateTimeException(\"The time format does not match yyyy-MM-dd HH:mm:ss\", e);\n        }\n    }\n\n    public static String convertToDateTimeFromTimestamp(Long timestamp) {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/apache/incubator-seata/blob/e01f97c6db397165050caa6764020410c2c8199a/console/src/main/java/org/apache/seata/mcp/core/utils/DateUtils.java#L23-L59","documentation":"DateUtils.convertToTimestampFromDate throws DateTimeException when the input string does not match the strict regex ^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$. The console MCP tools use this to parse 'yyyy-MM-dd' date parameters (e.g. for metrics/history queries), rejecting anything malformed — including '2026-2-3' (no zero padding) or '2026/02/03'.","triggerScenarios":"An MCP tool call passing a date parameter like '2026-02-03 12:00', '02/03/2026', '2026-13-01', or an empty string; convertToTimestampFromDate is called and isValidDate fails on the regex.","commonSituations":"LLM-driven MCP clients formatting dates loosely (unpadded month/day), users passing datetime strings where a date is expected, or locale-dependent date strings from tool wrappers.","solutions":["Pass the date strictly as zero-padded 'yyyy-MM-dd', e.g. '2026-08-14'","If you have a datetime string, use the corresponding convertToTimeStampFromDateTime path or truncate to the date part first","Validate with DateUtils.isValidDate(str) before invoking the MCP tool that requires the date","Reject month>12 or day>31 at the client side — the regex also refuses them"],"exampleFix":"// before\nLong ts = DateUtils.convertToTimestampFromDate(\"2026-8-4\"); // throws\n\n// after\nLong ts = DateUtils.convertToTimestampFromDate(\"2026-08-04\"); // ok","handlingStrategy":"type-guard","validationCode":"if (!DateUtils.isValidDate(dateStr)) throw new IllegalArgumentException(\"date must match yyyy-MM-dd, got: \" + dateStr);","typeGuard":"boolean isStrictDate(String s) { return s != null && s.matches(\"^\\\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$\"); }","tryCatchPattern":"try { ts = DateUtils.convertToTimestampFromDate(dateStr); } catch (DateTimeException e) { return toolError(\"Invalid date '\" + dateStr + \"', expected yyyy-MM-dd\"); }","preventionTips":["Always pre-check with DateUtils.isValidDate before calling","Zero-pad months and days at the client","Reject datetime strings before they reach date-only tools"],"tags":["seata","mcp","date-parsing","console"],"backgroundTag":null,"analyzedSha":"e01f97c6db397165050caa6764020410c2c8199a","analyzedAt":"2026-08-14T10:23:53.097Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}