{"record":{"id":"a7836267ca12eb0a","repo":"pentaho/pentaho-kettle","slug":"the-function-call-quarter-requires-1-argument","errorCode":null,"errorMessage":"The function call quarter requires 1 argument.","messagePattern":"The function call quarter 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":895,"sourceCode":"          return undefinedValue;\n        }\n        java.util.Date dArg1 = (java.util.Date) ArgList[0];\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 new RuntimeException( \"The function call quarter requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n\n  public static Object week( 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 );","sourceCodeStart":877,"sourceCodeEnd":913,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L877-L913","documentation":"Arity guard in ScriptAddedFunctions.quarter: the script call's ArgList length is not 1. The single expected argument is a java.util.Date from which the calendar month is mapped to quarter 1-4; any other argument count raises this RuntimeException.","triggerScenarios":"Calling quarter() with zero or two-plus arguments in a Script step, or an internal failure (bad cast) that bypasses the quarter branches and lands in the catch.","commonSituations":"Passing string dates; forgetting the argument when refactoring scripts; passing a Date plus a locale/format argument copied from another API.","solutions":["Call quarter() with exactly one Date argument.","Convert strings with str2date() first.","Null-check the date before the call.","Inspect e.toString() if the catch path fires with a cast error."],"exampleFix":"// before\nvar q = quarter(\"2026-09-13\");\n// after\nvar q = quarter(str2date(\"2026-09-13\", \"yyyy-MM-dd\"));","handlingStrategy":"validation","validationCode":"var q = (d != null) ? quarter(d) : null;","typeGuard":"function isKettleDate(v) { return v != null && v instanceof java.util.Date; }","tryCatchPattern":"try {\n  var q = quarter(d);\n} catch (e) {\n  Logger.LogBasic(\"quarter failed: \" + e.message);\n  q = null;\n}","preventionTips":["Pass exactly one Date argument.","Convert string dates with str2date().","Null-check optional fields.","Quarters are 1-4; no adjustment needed unlike month()."],"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"}