{"record":{"id":"dc4082c9a71ab309","repo":"pentaho/pentaho-kettle","slug":"the-function-call-week-requires-1-argument-dc4082","errorCode":null,"errorMessage":"The function call week requires 1 argument.","messagePattern":"The function call week 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":946,"sourceCode":"      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 );\n        return new Double( cal.get( Calendar.WEEK_OF_YEAR ) );\n      } else {\n        throw Context.reportRuntimeError( \"The function call week requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( e.toString() );\n    }\n  }\n\n  public static Object str2RegExp( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    String[] strArr = null;\n    if ( ArgList.length == 2 ) {\n      try {\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        String strToMatch = Context.toString( ArgList[0] );\n        Pattern p = Pattern.compile( Context.toString( ArgList[1] ) );","sourceCodeStart":928,"sourceCodeEnd":964,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L928-L964","documentation":"Argument-count guard in ScriptValuesAddedFunctions.week, which returns the ISO week number of a given Date as a Double. It fires when the script calls week with an argument count other than exactly 1; a Rhino runtime error is raised instead of computing the week. Fix by passing exactly one Date argument, e.g. week(orderDate).","triggerScenarios":"Calling week() with zero or multiple arguments in a modified JavaScript step, or with a value that cannot be cast to java.util.Date.","commonSituations":"Forgotten date argument, string dates not converted with str2Date(), locale-dependent week numbering surprises after the call succeeds.","solutions":["Call week() with exactly one Date argument.","Convert string dates with str2Date() before calling.","Null-check the field value.","Be aware week numbering depends on the JVM's locale/calendar; normalize if needed."],"exampleFix":"// before\nvar w = week();\n// after\nvar w = week(myDateField);","handlingStrategy":"validation","validationCode":"if (myDateField == null) throw 'week: date is null';\nvar w = week(myDateField);","typeGuard":"function isDate(v) { return v != null && v.getClass && String(v.getClass()) === 'class java.util.Date'; }","tryCatchPattern":"try { var w = week(myDateField); } catch (e) { var w = null; }","preventionTips":["Pass exactly one Date argument","Use str2Date() for string inputs","Account for locale-dependent week numbering","Null-check upstream date fields"],"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"}