{"record":{"id":"7f5f70a9f4f72a2e","repo":"xai-org/x-algorithm","slug":"date-string-format-error","errorCode":null,"errorMessage":"Date String Format Error:","messagePattern":"Date String Format Error:","errorType":"validation","errorClass":"DateStringParseFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/function/datetime/StringToTimeMs.java","lineNumber":75,"sourceCode":"  }\n\n  @Override\n  protected CacheLevel getCacheLevel() {\n    return CacheLevel.Global;\n  }\n\n  @Override\n  protected Object apply(Context<Runtime> context, List<Object> args) {\n\n    @SuppressWarnings(\"unchecked\")\n    String text = (String) args.get(0);\n    String format = (args.size() > 1) ? (String) args.get(1) : DEFAULT_FORMAT;\n    DateFormat dateFormat = TwitterDateFormat.apply(format);\n    dateFormat.setTimeZone(TimeZone.getTimeZone(DEFAULT_TIMEZONE));\n    try {\n      return dateFormat.parse(text).getTime();\n    } catch (ParseException ex) {\n      throw new DateStringParseFailure(\"Date String Format Error:\", ex);\n    }\n  }\n\n  private class DateStringParseFailure extends RuntimeException {\n    public DateStringParseFailure(String msg, Throwable throwable) {\n      super(msg, throwable);\n    }\n  }\n}\n","sourceCodeStart":57,"sourceCodeEnd":85,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/function/datetime/StringToTimeMs.java#L57-L85","documentation":"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.","triggerScenarios":"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\").","commonSituations":"Locale-dependent or ambiguous date formats, trailing whitespace, user-supplied free-text dates, or a format string typo (e.g. 'yyyy' vs 'yy').","solutions":["Pass an explicit format argument matching the input exactly, e.g. StringToTimeMs(s, \"dd/MM/yyyy\")","Trim/normalize the input string before parsing","Pre-validate the date string with a regex before calling StringToTimeMs"],"exampleFix":"// before\nStringToTimeMs(dateStr)\n// after\nStringToTimeMs(Trim(dateStr), \"yyyy-MM-dd\")","handlingStrategy":"try-catch","validationCode":"// rule-language: pre-validate shape\nIf(Matches(dateStr, \"^\\\\d{4}-\\\\d{2}-\\\\d{2}$\"), StringToTimeMs(dateStr, \"yyyy-MM-dd\"), fallbackMs)","typeGuard":"// host code\nboolean looksLikeDate(String s) { return s != null && s.trim().matches(\"\\\\d{4}-\\\\d{2}-\\\\d{2}\"); }","tryCatchPattern":"// 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","preventionTips":["Always pass an explicit format matching the data","Trim and normalize input strings before parsing","Pre-validate with a regex for high-volume user-supplied dates"],"tags":["botmaker","runtime","date-parsing","datetime","parse-exception"],"backgroundTag":"date-string-parse-failed","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}