caddyserver/caddy · warning
humanize: time cannot be parsed: %s
Error message
humanize: time cannot be parsed: %s
What it means
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.
Source
Thrown at modules/caddyhttp/templates/tplcontext.go:496
parts := strings.Split(formatType, ":")
switch parts[0] {
case "size":
dataint, dataerr := strconv.ParseUint(data, 10, 64)
if dataerr != nil {
return "", fmt.Errorf("humanize: size cannot be parsed: %s", dataerr.Error())
}
return humanize.Bytes(dataint), nil
case "time":
timelayout := time.RFC1123Z
if len(parts) > 1 {
timelayout = parts[1]
}
dataint, dataerr := time.Parse(timelayout, data)
if dataerr != nil {
return "", fmt.Errorf("humanize: time cannot be parsed: %s", dataerr.Error())
}
return humanize.Time(dataint), nil
}
return "", fmt.Errorf("no know function was given")
}
// funcMaybe invokes the plugged-in function named functionName if it is plugged in
// (is a module in the 'http.handlers.templates.functions' namespace). If it is not
// available, a log message is emitted.
//
// The first argument is the function name, and the rest of the arguments are
// passed on to the actual function.
//
// This function is useful for executing templates that use components that may be
// considered as optional in some cases (like during local development) where you do
// not want to require everyone to have a custom Caddy build to be able to execute
// your template.View on GitHub (pinned to 50e54ee279)
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
Example fix
<!-- before -->
{{ humanize "time" "2024-01-01" }}
<!-- after -->
{{ humanize "time:2006-01-02" "2024-01-01" }} Defensive patterns
Strategy: validation
Validate before calling
{{ $t := "2024-01-01" }}{{ if not (time.Parse "2006-01-02" $t) }}bad{{ end }}{{ humanize "time:2006-01-02" $t }} Prevention
- 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
When it happens
Trigger: {{ 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" }}.
Common situations: 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.
Related errors
- humanize: size cannot be parsed: %s
- no know function was given
- parsing environment file: %v
- can't parse line %d; line should be in KEY=VALUE format
- missing or empty key on line %d
AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15).
Data as JSON: /api/errors/10249acf7d1642c9.
Report an issue: GitHub.