{"record":{"id":"a2cd9a57cf9ccc47","repo":"pentaho/pentaho-kettle","slug":"the-function-call-isdate-requires-1-argument-a2cd9a","errorCode":null,"errorMessage":"The function call isDate requires 1 argument.","messagePattern":"The function call isDate requires 1 argument\\.","errorType":"exception","errorClass":"RhinoRuntimeError","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1509,"sourceCode":"  }\n\n  public static Object isDate( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n\n    if ( ArgList.length == 1 ) {\n      try {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return Context.getUndefinedValue();\n        }\n        /* java.util.Date d = (java.util.Date) */Context.jsToJava( ArgList[0], java.util.Date.class );\n        return Boolean.TRUE;\n      } catch ( Exception e ) {\n        return Boolean.FALSE;\n      }\n    } else {\n      throw Context.reportRuntimeError( \"The function call isDate requires 1 argument.\" );\n    }\n  }\n\n  public static Object decode( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    try {\n      if ( ArgList.length >= 2 ) {\n        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n          return Context.getUndefinedValue();\n        }\n        Object objToCompare = ArgList[0];\n        for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {\n          if ( ArgList[i].equals( objToCompare ) ) {\n            return ArgList[i + 1];\n          }\n        }","sourceCodeStart":1491,"sourceCodeEnd":1527,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1491-L1527","documentation":"The isDate JavaScript function attempts Context.jsToJava(value, java.util.Date.class) and returns FALSE if the cast fails; it only throws when called with anything other than exactly 1 argument. The thrown message indicates an arity violation in the isDate call, not that the value is not a date.","triggerScenarios":"isDate() with no arguments; isDate(dateValue, 'yyyy-MM-dd') — isDate takes no format argument, unlike some date helpers; passing two fields to check at once.","commonSituations":"Confusing isDate with other scripting languages' date-parse functions that accept a format string; attempting to validate a date string against an expected pattern in one call.","solutions":["Call isDate with exactly one argument","Remember isDate checks convertibility to java.util.Date, not string pattern compliance — drop any format argument","For string dates, parse with a Formatter/date function first, then test the result","Check multiple fields with one isDate call per field"],"exampleFix":"// before\nvar ok = isDate(dateStr, 'yyyy-MM-dd'); // 2 args -> throws\n// after\nvar ok = isDate(dateStr); // or parse/format the string separately","handlingStrategy":"type-guard","validationCode":"function isDateSafe(v) {\n  if (v === null || v === undefined) return false;\n  return isDate(v);\n}","typeGuard":"function isJsDate(v) { return Object.prototype.toString.call(v) === '[object Date]' && !isNaN(v.getTime()); }","tryCatchPattern":"try {\n  var ok = isDate(field);\n} catch (e) {\n  if (e.message.indexOf('isDate requires 1 argument') >= 0) {\n    // arity bug — isDate takes no format argument\n  }\n}","preventionTips":["Never pass a format/pattern argument to isDate — it only checks convertibility to java.util.Date","Parse formatted date strings with the appropriate date function first, then validate the result","Validate one field per call","Check the incoming field type in the step's field metadata before scripting"],"tags":["javascript","argument-count","pentaho","date"],"backgroundTag":"missing-required-argument","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}