xai-org/x-algorithm · error · DateStringParseFailure

Date String Format Error:

Error message

Date String Format Error:

What it means

StringToTimeMs parses a date string using the given (or default) format and timezone; when DateFormat.parse throws ParseException it is wrapped in DateStringParseFailure. The message is generic ('Date String Format Error:') with the ParseException chained as the cause carrying the error offset.

Source

Thrown at botmaker/src/java/com/twitter/botmaker/function/datetime/StringToTimeMs.java:75

  }

  @Override
  protected CacheLevel getCacheLevel() {
    return CacheLevel.Global;
  }

  @Override
  protected Object apply(Context<Runtime> context, List<Object> args) {

    @SuppressWarnings("unchecked")
    String text = (String) args.get(0);
    String format = (args.size() > 1) ? (String) args.get(1) : DEFAULT_FORMAT;
    DateFormat dateFormat = TwitterDateFormat.apply(format);
    dateFormat.setTimeZone(TimeZone.getTimeZone(DEFAULT_TIMEZONE));
    try {
      return dateFormat.parse(text).getTime();
    } catch (ParseException ex) {
      throw new DateStringParseFailure("Date String Format Error:", ex);
    }
  }

  private class DateStringParseFailure extends RuntimeException {
    public DateStringParseFailure(String msg, Throwable throwable) {
      super(msg, throwable);
    }
  }
}

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Pass an explicit format argument matching the input exactly, e.g. StringToTimeMs(s, "dd/MM/yyyy")
  2. Trim/normalize the input string before parsing
  3. Pre-validate the date string with a regex before calling StringToTimeMs

Example fix

// before
StringToTimeMs(dateStr)
// after
StringToTimeMs(Trim(dateStr), "yyyy-MM-dd")
Defensive patterns

Strategy: try-catch

Validate before calling

// rule-language: pre-validate shape
If(Matches(dateStr, "^\\d{4}-\\d{2}-\\d{2}$"), StringToTimeMs(dateStr, "yyyy-MM-dd"), fallbackMs)

Type guard

// host code
boolean looksLikeDate(String s) { return s != null && s.trim().matches("\\d{4}-\\d{2}-\\d{2}"); }

Try / catch

// host code: catch DateStringParseFailure (or its cause ParseException) around the evaluation, log the input string plus format, and apply a default timestamp — never retry the same string/format pair

Prevention

When it happens

Trigger: StringToTimeMs("31/12/2024") with the default format (which expects a different layout), or passing a custom format string that doesn't match the input, e.g. StringToTimeMs("2024-13-45", "yyyy-MM-dd").

Common situations: Locale-dependent or ambiguous date formats, trailing whitespace, user-supplied free-text dates, or a format string typo (e.g. 'yyyy' vs 'yy').

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/7f5f70a9f4f72a2e. Report an issue: GitHub.