{"record":{"id":"1f09e67930366f9e","repo":"pentaho/pentaho-kettle","slug":"the-function-call-week-requires-1-argument","errorCode":null,"errorMessage":"The function call week requires 1 argument.","messagePattern":"The function call week 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":916,"sourceCode":"      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 );\n        return new Double( cal.get( Calendar.WEEK_OF_YEAR ) );\n      } else {\n        throw new RuntimeException( \"The function call week requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n\n  public static Object str2RegExp( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object 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 undefinedValue;\n        }\n        String strToMatch = (String) ArgList[0];\n        Pattern p = Pattern.compile( (String) ArgList[1] );","sourceCodeStart":898,"sourceCodeEnd":934,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L898-L934","documentation":"week(date) returns Calendar.WEEK_OF_YEAR as a Double. It requires exactly one argument; with any other count it throws this RuntimeException, and other internal failures surface via the catch as e.toString().","triggerScenarios":"Calling week() with zero or multiple arguments in a Script step; passing a non-Date argument that fails the cast.","commonSituations":"Passing string dates; locale-dependent week numbering surprises (WEEK_OF_YEAR depends on the JVM's default Calendar locale); missing argument after refactoring.","solutions":["Call week() with exactly one Date argument.","Convert string inputs with str2date() first.","Null-check the date before calling week().","If week numbering looks wrong, verify the JVM locale/first-day-of-week settings rather than the call arity."],"exampleFix":"// before\nvar w = week(dateString);\n// after\nvar w = week(str2date(dateString, \"yyyy-MM-dd\"));","handlingStrategy":"validation","validationCode":"var w = (d != null) ? week(d) : null;","typeGuard":"function isKettleDate(v) { return v != null && v instanceof java.util.Date; }","tryCatchPattern":"try {\n  var w = week(d);\n} catch (e) {\n  Logger.LogBasic(\"week failed: \" + e.message);\n  w = null;\n}","preventionTips":["Pass exactly one Date argument.","Convert strings with str2date().","Null-check before calling.","Remember WEEK_OF_YEAR is locale-dependent (first day of week / minimal days)."],"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"}