{"record":{"id":"686f82e4ea347a54","repo":"kestra-io/kestra","slug":"the-hourofday-function-expects-a-date-argume","errorCode":null,"errorMessage":"The 'hourOfDay()' function expects a 'date' argument.","messagePattern":"The 'hourOfDay\\(\\)' function expects a 'date' argument\\.","errorType":"validation","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/HourOfDayFunction.java","lineNumber":37,"sourceCode":" * (e.g. {@code \"2025-01-06T14:30:00Z\"} or {@code \"2025-01-06T14:30:00+02:00\"} or\n * {@code \"2025-01-06T14:30:00\"}). The hour is taken from the local time component as written\n * in the string; no UTC normalization is performed. Plain date strings without a time\n * component are not supported.\n *\n * <p>\n * Usage: {@code {{ hourOfDay(date) }}}\n *\n * @param date ISO 8601 datetime string (with or without timezone offset)\n */\npublic class HourOfDayFunction implements KestraFunction {\n    public static final String NAME = \"hourOfDay\";\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 'hourOfDay()' function expects a 'date' argument.\", lineNumber, self.getName());\n        }\n\n        String dateStr = dateArg.toString();\n\n        try {\n            return ZonedDateTime.parse(dateStr).getHour();\n        } catch (DateTimeParseException e1) {\n            try {\n                return LocalDateTime.parse(dateStr).getHour();\n            } catch (DateTimeParseException e2) {\n                throw new PebbleException(e2, \"The 'hourOfDay()' function could not parse 'date': \" + e2.getMessage(), lineNumber, self.getName());\n            }\n        }\n    }\n\n    @Override\n    public List<String> getArgumentNames() {\n        return List.of(\"date\");","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/HourOfDayFunction.java#L19-L55","documentation":"Thrown by the 'hourOfDay()' function when the 'date' argument is null (args.get(\"date\") returns null). hourOfDay extracts the hour (0-23) from an ISO 8601 datetime; a missing date cannot be parsed, so it is rejected up front. Note the function reads args.get rather than checking containsKey, so a present-but-null value also triggers this.","triggerScenarios":"Calling hourOfDay() with no arguments; passing hourOfDay(inputs.missing) where the input resolves to null; passing an expression that evaluated to null.","commonSituations":"Binding 'date' to an optional input that was not provided; referencing a field that does not exist on an output/object; forgetting the argument entirely.","solutions":["Provide a concrete ISO 8601 datetime string: hourOfDay('2026-08-14T15:30:00Z').","If the date comes from a variable, ensure that variable is non-null before the call, or guard it with a default.","Use an expression that yields a fallback, e.g. hourOfDay(inputs.date ?? execution.startDate)."],"exampleFix":"# before - missing/optional input resolves to null\nh: \"{{ hourOfDay(inputs.maybe_date) }}\"\n# after - supply a default\nh: \"{{ hourOfDay(inputs.maybe_date ?? execution.startDate) }}\"","handlingStrategy":"validation","validationCode":"# Ensure 'date' is non-null before calling hourOfDay().\n# {{ (dateValue != null) ? hourOfDay(dateValue) : null }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide a 'date' argument to hourOfDay().","Bind 'date' to a guaranteed-present field, or supply a default via ??.","Confirm optional inputs are non-null before use.","Reference execution.startDate or task outputs known to be populated."],"tags":["pebble","hourofday","date","validation","missing-argument","time"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}