{"record":{"id":"69e197aa436a6ff8","repo":"pentaho/pentaho-kettle","slug":"the-function-call-date2str-requires-1-2-3-or-4-arguments","errorCode":null,"errorMessage":"The function call date2str requires 1, 2, 3, or 4 arguments.","messagePattern":"The function call date2str requires 1, 2, 3, or 4 arguments\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1177,"sourceCode":"\n          // If the timezone is not recognized, java will automatically\n          // take GMT.\n          TimeZone tz = TimeZone.getTimeZone( sArg4 );\n\n          if ( sArg3.length() == 2 ) {\n            Locale dfLocale = EnvUtil.createLocale( sArg3.toLowerCase() );\n            dfFormatter = new SimpleDateFormat( sArg2, dfLocale );\n            dfFormatter.setTimeZone( tz );\n            oRC = dfFormatter.format( dArg1 );\n          } else {\n            throw new RuntimeException( \"Locale is not 2 characters long.\" );\n          }\n        } catch ( Exception e ) {\n          throw new RuntimeException( \"Could not convert to the given local format.\" );\n        }\n        break;\n      default:\n        throw new RuntimeException( \"The function call date2str requires 1, 2, 3, or 4 arguments.\" );\n    }\n    return oRC;\n  }\n\n  public static Object isRegExp( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n\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 undefinedValue;\n      }\n      String strToMatch = (String) ArgList[0];\n      for ( int i = 1; i < ArgList.length; i++ ) {\n        Pattern p = Pattern.compile( (String) ArgList[i] );\n        Matcher m = p.matcher( strToMatch );\n        if ( m.matches() ) {","sourceCodeStart":1159,"sourceCodeEnd":1195,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1159-L1195","documentation":"Thrown by date2str() when it is called with more than 4 arguments; the function's switch only handles signatures with 1 to 4 arguments (date, [format], [locale], [timezone]) and the default branch rejects anything else.","triggerScenarios":"Invoking date2str with 5+ arguments in a Script step, e.g. date2str(d, fmt, loc, tz, extra).","commonSituations":"Copy-pasted JavaScript from another environment (native JS Date formatting habits), or mistakenly appending extra parameters expecting them to be ignored like in some JS engines.","solutions":["Remove extra arguments; use at most 4: date, format, locale, timezone.","If you need custom behavior beyond the 4 supported parameters, format in two steps or use a User Defined Java Expression / UDF."],"exampleFix":"// before\ndate2str(d, 'yyyy-MM-dd', 'en', 'UTC', 'extra')\n// after\ndate2str(d, 'yyyy-MM-dd', 'en', 'UTC')","handlingStrategy":"validation","validationCode":"function safeDate2str() {\n  var args = Array.prototype.slice.call(arguments);\n  if (args.length > 4) args = args.slice(0, 4);\n  if (args.length < 1) throw new Error('date2str needs a date');\n  return date2str.apply(null, args);\n}","typeGuard":null,"tryCatchPattern":"try { return date2str(d, fmt, loc, tz); }\ncatch (e) { if (/requires 1, 2, 3, or 4/.test(e.message)) return date2str(d); throw e; }","preventionTips":["Remember the maximum signature: date, format, locale, timezone.","Never pass cc-style extra parameters hoping they are ignored.","Use the Mail or Java-filter steps for features beyond the 4 supported args."],"tags":["javascript","scripting-step","argument-count","date-formatting"],"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"}