{"record":{"id":"d21d50b7c738abc5","repo":"kestra-io/kestra","slug":"the-hourofday-function-could-not-parse-date","errorCode":null,"errorMessage":"The 'hourOfDay()' function could not parse 'date': {e2.getMessage()}","messagePattern":"The 'hourOfDay\\(\\)' function could not parse 'date': (.+?)","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/HourOfDayFunction.java","lineNumber":48,"sourceCode":"    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\");\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    }\n}","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/HourOfDayFunction.java#L30-L66","documentation":"Thrown by 'hourOfDay()' when the date string cannot be parsed as either a ZonedDateTime (first attempt) or a LocalDateTime (second attempt). Both DateTimeParseException failures are caught; the second's message is wrapped into the PebbleException. This means the value was non-null but not a recognizable ISO 8601 datetime.","triggerScenarios":"Passing a date-only string ('2026-08-14'), a time-only string ('15:30:00'), a locale-formatted date ('14/08/2026'), an epoch number as a string, or any non-ISO 8601 textual date.","commonSituations":"Using a date format from another system without converting to ISO 8601; passing a date-only when a datetime is required; locale-specific formats (DD/MM/YYYY vs MM/DD/YYYY); passing a timestamp/epoch.","solutions":["Provide a full ISO 8601 datetime string with an offset for best results: hourOfDay('2026-08-14T15:30:00+02:00').","Pre-format the date into ISO 8601 before the call using a task or expression.","If you only have a date, append a time component (e.g. T00:00:00) so LocalDateTime.parse succeeds.","Avoid locale/epoch formats; convert them upstream."],"exampleFix":"# before - non-ISO format\nh: \"{{ hourOfDay('14/08/2026 15:30') }}\"\n# after - ISO 8601\nh: \"{{ hourOfDay('2026-08-14T15:30:00Z') }}\"","handlingStrategy":"validation","validationCode":"# Light ISO 8601 pre-check before calling hourOfDay().\n# {{ (dateValue matches '^\\\\d{4}-\\\\d{2}-\\\\d{2}T.*') ? hourOfDay(dateValue) : hourOfDay(dateValue ~ 'T00:00:00') }}","typeGuard":null,"tryCatchPattern":"# Pebble has no try/catch. In a wrapper task, catch DateTimeParseException and return a sentinel (e.g. -1) or log the bad input.","preventionTips":["Provide a full ISO 8601 datetime with an offset for best reliability.","Pre-format dates into ISO 8601 upstream of the call.","Append a time component (T00:00:00) if only a date is available.","Avoid locale formats (DD/MM/YYYY) and epoch strings."],"tags":["pebble","hourofday","date","parse-error","iso8601","time","validation"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}