{"record":{"id":"6643d9125dde2cd7","repo":"pentaho/pentaho-kettle","slug":"the-function-call-month-requires-1-argument","errorCode":null,"errorMessage":"The function call month requires 1 argument.","messagePattern":"The function call month requires 1 argument\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":862,"sourceCode":"      throw new RuntimeException( e.toString() );\n    }\n  }\n\n  public static Object month( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 ) {\n        if ( isNull( ArgList[0] ) ) {\n          return new Double( Double.NaN );\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return undefinedValue;\n        }\n        java.util.Date dArg1 = (java.util.Date) ArgList[0];\n        Calendar cal = Calendar.getInstance();\n        cal.setTime( dArg1 );\n        return new Double( cal.get( Calendar.MONTH ) );\n      } else {\n        throw new RuntimeException( \"The function call month requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n\n  }\n\n  public static Object quarter( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 ) {\n        if ( isNull( ArgList[0] ) ) {\n          return new Double( Double.NaN );\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return undefinedValue;\n        }\n        java.util.Date dArg1 = (java.util.Date) ArgList[0];\n        Calendar cal = Calendar.getInstance();","sourceCodeStart":844,"sourceCodeEnd":880,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L844-L880","documentation":"Arity guard in ScriptAddedFunctions.month: the script call's ArgList length is not 1. The single expected argument is a java.util.Date; with correct arity the function returns the Calendar month as a Double, otherwise this RuntimeException is thrown to the script engine.","triggerScenarios":"Calling month() with zero or multiple arguments in a Script step, or an argument flow that fails the ArgList.length == 1 check.","commonSituations":"Expecting 1-based months (Calendar.MONTH is 0-based, January = 0); passing string dates; chaining calls with wrong arity.","solutions":["Call month() with exactly one Date argument.","Remember the result is 0-based; add 1 for human-readable months.","Convert strings with str2date() first.","Null-check the date before the call."],"exampleFix":"// before\nvar m = month();\n// after\nvar m = month(dateField) + 1; // Calendar.MONTH is 0-based","handlingStrategy":"validation","validationCode":"var m = (d != null) ? month(d) + 1 : null; // Calendar.MONTH is 0-based","typeGuard":"function isKettleDate(v) { return v != null && v instanceof java.util.Date; }","tryCatchPattern":"try {\n  var m = month(d);\n} catch (e) {\n  Logger.LogBasic(\"month failed: \" + e.message);\n  m = null;\n}","preventionTips":["Pass exactly one Date argument.","Remember the 0-based result; add 1 for display.","Convert strings via str2date().","Null-check before calling."],"tags":["javascript","script-step","argument-count","date","pentaho-kettle"],"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"}