{"record":{"id":"6fbcf42432ff3b2a","repo":"pentaho/pentaho-kettle","slug":"the-function-call-quarter-requires-1-argument-6fbcf4","errorCode":null,"errorMessage":"The function call quarter requires 1 argument.","messagePattern":"The function call quarter requires 1 argument\\.","errorType":"exception","errorClass":"JavaScriptException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":925,"sourceCode":"          return Context.getUndefinedValue();\n        }\n        java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );\n        Calendar cal = Calendar.getInstance();\n        cal.setTime( dArg1 );\n\n        // Patch by Ingo Klose: calendar months start at 0 in java.\n        int iMonth = cal.get( Calendar.MONTH );\n        if ( iMonth <= 2 ) {\n          return new Double( 1 );\n        } else if ( iMonth <= 5 ) {\n          return new Double( 2 );\n        } else if ( iMonth <= 8 ) {\n          return new Double( 3 );\n        } else {\n          return new Double( 4 );\n        }\n      } else {\n        throw Context.reportRuntimeError( \"The function call quarter requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( e.toString() );\n    }\n  }\n\n  public static Object week( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function 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 Context.getUndefinedValue();\n        }\n        java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );\n        Calendar cal = Calendar.getInstance();\n        cal.setTime( dArg1 );","sourceCodeStart":907,"sourceCodeEnd":943,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L907-L943","documentation":"Argument-count guard in ScriptValuesAddedFunctions.quarter, which maps a Date's month to its calendar quarter (1-4). It fires when the script calls quarter with an argument count other than exactly 1; Rhino raises a runtime error before any date computation. Fix by passing exactly one Date argument, e.g. quarter(orderDate).","triggerScenarios":"Calling quarter() with zero or multiple arguments in a modified JavaScript step, or passing a non-Date value that fails the internal month extraction.","commonSituations":"Omitting the date argument when adapting SQL-style scripts, passing a string date, or null fields arriving from upstream steps.","solutions":["Call quarter() with exactly one Date argument.","Use str2Date() to convert string dates first.","Null-check the date field before the call.","Verify the incoming field is a Date type, not a string."],"exampleFix":"// before\nvar q = quarter('2024-05-01');\n// after\nvar q = quarter(str2Date('2024-05-01', 'yyyy-MM-dd'));","handlingStrategy":"validation","validationCode":"if (myDateField == null) throw 'quarter: date is null';\nvar q = quarter(myDateField);","typeGuard":"function isDate(v) { return v != null && v.getClass && String(v.getClass()) === 'class java.util.Date'; }","tryCatchPattern":"try { var q = quarter(myDateField); } catch (e) { var q = null; }","preventionTips":["Pass exactly one Date argument","Convert strings with str2Date() first","Null-check fields before the call","Verify quarter expectations (1-4) when consuming the result"],"tags":["javascript","rhino","date-functions"],"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"}