{"id":"a280921765345288","repo":"gohugoio/hugo","slug":"invalid-arguments-supplied-to-time","errorCode":null,"errorMessage":"invalid arguments supplied to `time`","messagePattern":"invalid arguments supplied to `time`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/time/init.go","lineNumber":55,"sourceCode":"\t\t\tContext: func(cctx context.Context, args ...any) (any, error) {\n\t\t\t\t// Handle overlapping \"time\" namespace and func.\n\t\t\t\t//\n\t\t\t\t// If no args are passed to `time`, assume namespace usage and\n\t\t\t\t// return namespace context.\n\t\t\t\t//\n\t\t\t\t// If args are passed, call AsTime().\n\n\t\t\t\tswitch len(args) {\n\t\t\t\tcase 0:\n\t\t\t\t\treturn ctx, nil\n\t\t\t\tcase 1:\n\t\t\t\t\treturn ctx.AsTime(args[0])\n\t\t\t\tcase 2:\n\t\t\t\t\treturn ctx.AsTime(args[0], args[1])\n\n\t\t\t\t// 3 or more arguments. Currently not supported.\n\t\t\t\tdefault:\n\t\t\t\t\treturn nil, errors.New(\"invalid arguments supplied to `time`\")\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\n\t\tns.AddMethodMapping(ctx.AsTime,\n\t\t\tnil,\n\t\t\t[][2]string{\n\t\t\t\t{`{{ (time \"2015-01-21\").Year }}`, `2015`},\n\t\t\t},\n\t\t)\n\n\t\tns.AddMethodMapping(ctx.Duration,\n\t\t\t[]string{\"duration\"},\n\t\t\t[][2]string{\n\t\t\t\t{`{{ mul 60 60 | duration \"second\" }}`, `1h0m0s`},\n\t\t\t},\n\t\t)\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/time/init.go#L37-L73","documentation":"The `time` identifier in Hugo templates is both a namespace and a function. The dispatcher in tpl/time/init.go returns the namespace with 0 args, calls AsTime with 1 arg (value) or 2 args (value, location), and rejects 3 or more arguments with this error since no overload exists for that arity.","triggerScenarios":"Calling `{{ time \"2024-01-01\" \"UTC\" \"extra\" }}` or otherwise piping/passing three or more arguments to `time` — e.g. `{{ time .Date .Site.Params.tz .Something }}` or a mistaken pipe that appends an extra final argument.","commonSituations":"Confusing `time` with `time.Format` or `dateFormat` and passing a layout string as a third argument; pipeline misuse where `|` appends the piped value as an extra argument (`{{ \"2024-01-01\" | time \"UTC\" \"x\" }}`); porting templates from other engines with different date-function signatures.","solutions":["Call `time` with one argument (the value) or two (value, timezone): `{{ time \"2024-01-01\" \"America/New_York\" }}`.","If you meant to format, convert first then format: `{{ (time .Date).Format \"2006-01-02\" }}` or use `time.Format`.","Check pipelines — a piped value counts as the last argument, so remove redundant explicit arguments."],"exampleFix":"<!-- before -->\n{{ time \"2024-01-01\" \"UTC\" \"2006-01-02\" }}\n<!-- after -->\n{{ (time \"2024-01-01\" \"UTC\").Format \"2006-01-02\" }}","handlingStrategy":"validation","validationCode":"{{ $d := .Params.date }}\n{{ if $d }}{{ $t := time.AsTime $d }}{{ end }}","typeGuard":"{{ if or (reflect.IsMap $d) (reflect.IsSlice $d) }}{{ warnf \"time needs a string or time.Time, got collection\" }}{{ else }}{{ time.AsTime $d }}{{ end }}","tryCatchPattern":"{{ with try (time.AsTime .Params.eventDate) }}{{ if .Err }}{{ errorf \"invalid date in %s: %s\" $.File.Path .Err }}{{ else }}{{ .Value.Format \"2006-01-02\" }}{{ end }}{{ end }}","preventionTips":["Pass a parseable date string or time.Time, never a map/slice/nil from unchecked front matter","Guard optional date params with `with` before converting","Prefer .Date/.PublishDate page fields, which Hugo has already parsed"],"tags":["hugo","templates","time","arguments"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}