{"record":{"id":"687f96ddf3585a97","repo":"kestra-io/kestra","slug":"the-monthofyear-function-could-not-parse-date","errorCode":null,"errorMessage":"The 'monthOfYear()' function could not parse 'date': %s","messagePattern":"The 'monthOfYear\\(\\)' function could not parse 'date': (.+?)","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/MonthOfYearFunction.java","lineNumber":38,"sourceCode":" *\n * @param date any valid ISO 8601 date or datetime string\n */\npublic class MonthOfYearFunction implements KestraFunction {\n    public static final String NAME = \"monthOfYear\";\n\n    @Override\n    public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {\n        Object dateArg = args.get(\"date\");\n\n        if (dateArg == null) {\n            throw new PebbleException(null, \"The 'monthOfYear()' function expects a 'date' argument.\", lineNumber, self.getName());\n        }\n\n        LocalDate localDate;\n        try {\n            localDate = DateUtils.parseLocalDate(dateArg.toString());\n        } catch (InternalException e) {\n            throw new PebbleException(e, \"The 'monthOfYear()' function could not parse 'date': \" + e.getMessage(), lineNumber, self.getName());\n        }\n\n        return localDate.getMonthValue();\n    }\n\n    @Override\n    public List<String> getArgumentNames() {\n        return List.of(\"date\");\n    }\n\n    @Override\n    // HashMap is required here because Map.of() does not allow null values,\n    // and null defaults indicate arguments with no meaningful autocompletion default.\n    public Map<String, String> getArgumentDefaults() {\n        HashMap<String, String> defaults = new HashMap<>();\n        defaults.put(\"date\", null);\n        return defaults;\n    }","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/MonthOfYearFunction.java#L20-L56","documentation":"The monthOfYear(date) function calls DateUtils.parseLocalDate, which attempts LocalDate.parse, then ZonedDateTime.parse, then LocalDateTime.parse — all expecting ISO 8601. If all three fail, the InternalException is wrapped in this PebbleException with the original DateTimeException message appended.","triggerScenarios":"Passing '06/15/2024', '15.06.2024', 'June 15 2024', epoch timestamps, or any non-ISO 8601 string.","commonSituations":"An upstream task or external API provides dates in regional or custom formats. The user assumes natural-language date parsing is supported.","solutions":["Convert the date to ISO 8601 format (yyyy-MM-dd) before calling monthOfYear.","Check the appended e.getMessage() for the exact parse failure detail.","Use an intermediate task or expression to reformat the date if it comes from an external source."],"exampleFix":"# before\nvalue: \"{{ monthOfYear('15/06/2024') }}\"\n# after\nvalue: \"{{ monthOfYear('2024-06-15') }}\"","handlingStrategy":"validation","validationCode":"# Validate ISO 8601 format before calling monthOfYear:\n{% set datePattern = /^\\d{4}-\\d{2}-\\d{2}(T.*)?$/ %}\n{% if myDateVar matches datePattern %}\n  {{ monthOfYear(myDateVar) }}\n{% else %}\n  {{ throw('date must be ISO 8601') }}\n{% endif %}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize all date inputs to ISO 8601 format in upstream tasks.","Avoid locale-specific date formats in Pebble expressions.","Inspect the appended e.getMessage() for parse failure details."],"tags":["pebble-function","date-parsing","monthofyear"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}