MyCATApache/Mycat-Server · error · IllegalArgumentException

Interval string does not match day-time format of 'd…

Error message

Interval string does not match day-time format of 'd h:m:s.n': 

What it means

Thrown by CalendarInterval.fromDayTimeString when the trimmed input is non-null but does not match dayTimePattern, i.e. it is not of the form [-]d HH:mm:ss.nnnnnnnnn. This is a format validation guard: the string was present but syntactically invalid (missing time parts, bad separators, non-numeric fields, etc.). The message includes the offending input so callers can see exactly which value failed; fix by supplying a day-time interval string like '3 12:30:45.123'.

Solutions

  1. Rewrite the literal as 'd h:m:s.n', e.g. '1 12:30:45.123'
  2. Drop unsupported extra precision (max 9 nanosecond digits)
  3. Trim whitespace and remove surrounding quotes before parsing

Example fix

// before
CalendarInterval iv = CalendarInterval.fromDayTimeString("1 day 12 hours");
// after
CalendarInterval iv = CalendarInterval.fromDayTimeString("1 12:00:00.000");
Defensive patterns

Strategy: validation

Validate before calling

private static final Pattern DT = Pattern.compile("^-?\\d+ \\d{1,2}:\\d{1,2}:\\d{1,2}\\.\\d{1,9}$");
static void requireDayTime(String s) {
  if (s == null || !DT.matcher(s.trim()).matches())
    throw new IllegalArgumentException("expected 'd h:m:s.n', got: " + s);
}

Type guard

static boolean isDayTimeString(String s) {
  return s != null && s.trim().matches("-?\\d+ \\d{1,2}:\\d{1,2}:\\d{1,2}(\\.\\d{1,9})?");
}

Try / catch

try {
  iv = CalendarInterval.fromDayTimeString(s);
} catch (IllegalArgumentException e) {
  log.warn("Skipping malformed day-time interval '{}'", s);
  iv = CalendarInterval.ZERO;
}

Prevention

When it happens

Trigger: Calling fromDayTimeString with strings like "1 day", "12:30", "1 12:30:45.123.456", "01:02:03" (no day part).

Common situations: Interval literals copied from PostgreSQL/Hive in a different syntax, missing time components, extra sub-second digits, locale-formatted durations.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/7a1c8624d59150bf. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java:145

      }
    }
    return result;
  }

  /**
   * Parse dayTime string in form: [-]d HH:mm:ss.nnnnnnnnn
   *
   * adapted from HiveIntervalDayTime.valueOf
   */
  public static CalendarInterval fromDayTimeString(String s) throws IllegalArgumentException {
    CalendarInterval result = null;
    if (s == null) {
      throw new IllegalArgumentException("Interval day-time string was null");
    }
    s = s.trim();
    Matcher m = dayTimePattern.matcher(s);
    if (!m.matches()) {
      throw new IllegalArgumentException(
        "Interval string does not match day-time format of 'd h:m:s.n': " + s);
    } else {
      try {
        int sign = m.group(1) != null && m.group(1).equals("-") ? -1 : 1;
        long days = toLongWithRange("day", m.group(2), 0, Integer.MAX_VALUE);
        long hours = toLongWithRange("hour", m.group(3), 0, 23);
        long minutes = toLongWithRange("minute", m.group(4), 0, 59);
        long seconds = toLongWithRange("second", m.group(5), 0, 59);
        // Hive allow nanosecond precision interval
        long nanos = toLongWithRange("nanosecond", m.group(7), 0L, 999999999L);
        result = new CalendarInterval(0, sign * (
          days * MICROS_PER_DAY + hours * MICROS_PER_HOUR + minutes * MICROS_PER_MINUTE +
          seconds * MICROS_PER_SECOND + nanos / 1000L));
      } catch (Exception e) {
        throw new IllegalArgumentException(
          "Error parsing interval day-time string: " + e.getMessage(), e);
      }
    }

View on GitHub (pinned to 65f8d8beb7)