apache/incubator-seata · error · DateTimeException

The time format does not match yyyy-MM-dd

Error message

The time format does not match yyyy-MM-dd

What it means

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'.

Source

Thrown at console/src/main/java/org/apache/seata/mcp/core/utils/DateUtils.java:41

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.regex.Pattern;

public class DateUtils {

    public static final Long ONE_DAY_TIMESTAMP = 86400000L;

    private static final Pattern DATE_PATTERN = Pattern.compile("^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$");

    public static boolean isValidDate(String dateStr) {
        return DATE_PATTERN.matcher(dateStr).matches();
    }

    public static long convertToTimestampFromDate(String dateStr) {
        if (!isValidDate(dateStr)) {
            throw new DateTimeException("The time format does not match yyyy-MM-dd");
        }
        LocalDate date = LocalDate.parse(dateStr);
        ZonedDateTime zonedDateTime = date.atStartOfDay(ZoneId.systemDefault());
        return zonedDateTime.toInstant().toEpochMilli();
    }

    public static long convertToTimeStampFromDateTime(String dateTimeStr) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        try {
            LocalDateTime dateTime = LocalDateTime.parse(dateTimeStr, formatter);
            return dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        } catch (DateTimeParseException e) {
            throw new DateTimeException("The time format does not match yyyy-MM-dd HH:mm:ss", e);
        }
    }

    public static String convertToDateTimeFromTimestamp(Long timestamp) {

View on GitHub (pinned to e01f97c6db)

Solutions

  1. Pass the date strictly as zero-padded 'yyyy-MM-dd', e.g. '2026-08-14'
  2. If you have a datetime string, use the corresponding convertToTimeStampFromDateTime path or truncate to the date part first
  3. Validate with DateUtils.isValidDate(str) before invoking the MCP tool that requires the date
  4. Reject month>12 or day>31 at the client side — the regex also refuses them

Example fix

// before
Long ts = DateUtils.convertToTimestampFromDate("2026-8-4"); // throws

// after
Long ts = DateUtils.convertToTimestampFromDate("2026-08-04"); // ok
Defensive patterns

Strategy: type-guard

Validate before calling

if (!DateUtils.isValidDate(dateStr)) throw new IllegalArgumentException("date must match yyyy-MM-dd, got: " + dateStr);

Type guard

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])$"); }

Try / catch

try { ts = DateUtils.convertToTimestampFromDate(dateStr); } catch (DateTimeException e) { return toolError("Invalid date '" + dateStr + "', expected yyyy-MM-dd"); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/incubator-seata@e01f97c6db (2026-08-14). Data as JSON: /api/errors/493da3683c8b63f0. Report an issue: GitHub.