{"record":{"id":"10249acf7d1642c9","repo":"caddyserver/caddy","slug":"humanize-time-cannot-be-parsed-s","errorCode":null,"errorMessage":"humanize: time cannot be parsed: %s","messagePattern":"humanize: time cannot be parsed: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"modules/caddyhttp/templates/tplcontext.go","lineNumber":496,"sourceCode":"\tparts := strings.Split(formatType, \":\")\n\n\tswitch parts[0] {\n\tcase \"size\":\n\t\tdataint, dataerr := strconv.ParseUint(data, 10, 64)\n\t\tif dataerr != nil {\n\t\t\treturn \"\", fmt.Errorf(\"humanize: size cannot be parsed: %s\", dataerr.Error())\n\t\t}\n\t\treturn humanize.Bytes(dataint), nil\n\n\tcase \"time\":\n\t\ttimelayout := time.RFC1123Z\n\t\tif len(parts) > 1 {\n\t\t\ttimelayout = parts[1]\n\t\t}\n\n\t\tdataint, dataerr := time.Parse(timelayout, data)\n\t\tif dataerr != nil {\n\t\t\treturn \"\", fmt.Errorf(\"humanize: time cannot be parsed: %s\", dataerr.Error())\n\t\t}\n\t\treturn humanize.Time(dataint), nil\n\t}\n\n\treturn \"\", fmt.Errorf(\"no know function was given\")\n}\n\n// funcMaybe invokes the plugged-in function named functionName if it is plugged in\n// (is a module in the 'http.handlers.templates.functions' namespace). If it is not\n// available, a log message is emitted.\n//\n// The first argument is the function name, and the rest of the arguments are\n// passed on to the actual function.\n//\n// This function is useful for executing templates that use components that may be\n// considered as optional in some cases (like during local development) where you do\n// not want to require everyone to have a custom Caddy build to be able to execute\n// your template.","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/templates/tplcontext.go#L478-L514","documentation":"Returned by the templates module's humanize function, format 'time', when time.Parse fails on the input using the given layout (default RFC1123Z, or the layout after the colon like 'time:2006-01-02'). The error string from time.Parse is embedded.","triggerScenarios":"{{ humanize \"time\" \"2024-01-01\" }} with the default RFC1123Z layout mismatch, or a custom layout that does not match the data, e.g. {{ humanize \"time:2006-01-02\" \"Jan 1 2024\" }}.","commonSituations":"Feeding ISO dates while forgetting the default is RFC1123Z, mixing up Go reference-time layouts (using yyyy-mm-dd instead of 2006-01-02), or an empty/placeholder-derived timestamp string.","solutions":["Specify the matching Go layout: {{ humanize \"time:2006-01-02\" \"2024-01-01\" }}","Or pass the time in RFC1123Z form ('Mon, 02 Jan 2006 15:04:05 -0700')","Use Go's reference date (Jan 2 15:04:05 2006 MST) when writing the layout, never yyyy/dd style","Default empty inputs to a known timestamp before humanizing"],"exampleFix":"<!-- before -->\n{{ humanize \"time\" \"2024-01-01\" }}\n\n<!-- after -->\n{{ humanize \"time:2006-01-02\" \"2024-01-01\" }}","handlingStrategy":"validation","validationCode":"{{ $t := \"2024-01-01\" }}{{ if not (time.Parse \"2006-01-02\" $t) }}bad{{ end }}{{ humanize \"time:2006-01-02\" $t }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass an explicit layout: humanize \"time:2006-01-02\"","Remember Go reference-time layouts (2006-01-02), not yyyy-mm-dd","Standardize timestamp formats emitted by backend data feeds"],"tags":["caddy","templates","humanize","time","parsing"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}