{"record":{"id":"8054a72c76175698","repo":"stanfordnlp/CoreNLP","slug":"could-not-parse-date-string-docdate","errorCode":null,"errorMessage":"Could not parse date string: [${docDate}]","messagePattern":"Could not parse date string: \\[(.+?)\\]","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/time/TimeExpressionExtractorImpl.java","lineNumber":101,"sourceCode":"          }\n        } else {\n          SimpleDateFormat dateFormat = new SimpleDateFormat(\"yyyy-MM-dd:hh:mm:ss\");\n          docDate = dateFormat.format(cal.getTime());\n        }\n      }\n    } else {\n      timeIndex = new SUTime.TimeIndex();\n    }\n    if (StringUtils.isNullOrEmpty(docDate)) {\n      docDate = null;\n    }\n    if (timeIndex.docDate == null && docDate != null) {\n      try {\n        // TODO: have more robust parsing of document date?  docDate may not have century....\n        // TODO: if docDate didn't change, we can cache the parsing of the docDate and not repeat it for every sentence\n        timeIndex.docDate = SUTime.parseDateTime(docDate,true);\n      } catch (Exception e) {\n        throw new RuntimeException(\"Could not parse date string: [\" + docDate + \"]\", e);\n      }\n    }\n    String sectionDate = annotation.get(CoreAnnotations.SectionDateAnnotation.class);\n    String refDate = (sectionDate != null) ? sectionDate: docDate;\n    return extractTimeExpressionCoreMaps(annotation, refDate, timeIndex);\n  }\n\n  @Override\n  public List<CoreMap> extractTimeExpressionCoreMaps(CoreMap annotation, String docDate) {\n    SUTime.TimeIndex timeIndex = new SUTime.TimeIndex();\n    return extractTimeExpressionCoreMaps(annotation, docDate, timeIndex);\n  }\n\n  public List<CoreMap> extractTimeExpressionCoreMaps(CoreMap annotation, String docDate, SUTime.TimeIndex timeIndex) {\n    List<TimeExpression> timeExpressions = extractTimeExpressions(annotation, docDate, timeIndex);\n    return toCoreMaps(annotation, timeExpressions, timeIndex);\n  }\n","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/time/TimeExpressionExtractorImpl.java#L83-L119","documentation":"Thrown when the document date string passed to extractTimeExpressionCoreMaps cannot be parsed by SUTime.parseDateTime into a usable date. The CoreMap extraction pipeline needs a reference date to resolve relative temporal expressions (e.g. \"next week\"), and an unparseable docDate makes that impossible. It is wrapped in a RuntimeException so it escapes as an unchecked failure during annotation.","triggerScenarios":"Calling TimeExpressionExtractorImpl.extractTimeExpressionCoreMaps(annotation, docDate, timeIndex) with a docDate string that is not in an ISO-8601-like format SUTime accepts (e.g. \"March 3rd, 2020\", \"03/2020\", empty-but-non-null string).","commonSituations":"DocDate annotation populated by a custom document reader from a non-ISO header field (PDF metadata, email Date headers, news article bylines), or dates missing the century (e.g. \"990304\"), a case the TODO comments explicitly flag.","solutions":["Normalize docDate to ISO 8601 (yyyy-MM-dd or full ISO datetime) before calling the extractor.","Catch the RuntimeException and re-run extraction with docDate=null so expressions resolve against no reference date.","Pre-validate the string with a strict date parser (Joda DateTimeFormat or java.time) and sanitize before annotation.","Prepend a century if the string is 6 digits (yyyy can be omitted per the source TODO)."],"exampleFix":"// before\nString docDate = metadata.get(\"creation-date\"); // \"Mar 3, 2020\"\nextractor.extractTimeExpressionCoreMaps(annotation, docDate, timeIndex);\n\n// after\nString docDate = metadata.get(\"creation-date\");\nDateTime dt = DateTimeFormat.forPattern(\"MMM d, yyyy\").parseDateTime(docDate);\nString iso = ISODateTimeFormat.date().print(dt); // \"2020-03-03\"\nextractor.extractTimeExpressionCoreMaps(annotation, iso, timeIndex);","handlingStrategy":"validation","validationCode":"static boolean isValidDocDate(String s) {\n  if (s == null) return true; // null is allowed\n  try { ISODateTimeFormat.dateParser().parseDateTime(s); return true; }\n  catch (IllegalArgumentException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  extractor.extractTimeExpressionCoreMaps(annotation, docDate, timeIndex);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Could not parse date string\")) {\n    extractor.extractTimeExpressionCoreMaps(annotation, null, timeIndex); // degrade gracefully\n  } else throw e;\n}","preventionTips":["Always emit ISO 8601 (yyyy-MM-dd) doc dates from your document readers.","Pad 2-digit years / add missing century before annotation.","Log-and-fallback to null docDate instead of aborting the whole pipeline."],"tags":["date-parsing","runtime-exception","sutime","nlp"],"backgroundTag":"invalid-date-format","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}