gohugoio/hugo · error

invalid arguments supplied to `time`

Error message

invalid arguments supplied to `time`

What it means

Thrown by the `time` template namespace/func dispatcher when three or more arguments are passed (tpl/time/init.go:54-55). The time func accepts zero (namespace), one (value), or two (value + layout) arguments only; more than two is unsupported.

Solutions

  1. Reduce to at most two arguments: {{ time "2015-01-21" }} or {{ time .Date "2006-01-02" }}.
  2. For timezone handling, use the result's .In method or the langs/location config rather than a third arg.

Example fix

// before
{{ time .Date .Layout .TZ }}
// after
{{ time .Date .Layout }}
Defensive patterns

Strategy: validation

Validate before calling

{{ time .Date }}

Prevention

When it happens

Trigger: Calling {{ time "2015-01-21" "2006-01-02" "extra" }} or {{ time .Date .Layout .TZ }} with three or more args.

Common situations: Trying to pass a timezone as a third argument (not supported); copy-pasting examples with extra layout fields; misunderstanding the namespace-vs-func overload.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/a280921765345288. Report an issue: GitHub.

Appendix: source

Thrown at tpl/time/init.go:55

			Context: func(cctx context.Context, args ...any) (any, error) {
				// Handle overlapping "time" namespace and func.
				//
				// If no args are passed to `time`, assume namespace usage and
				// return namespace context.
				//
				// If args are passed, call AsTime().

				switch len(args) {
				case 0:
					return ctx, nil
				case 1:
					return ctx.AsTime(args[0])
				case 2:
					return ctx.AsTime(args[0], args[1])

				// 3 or more arguments. Currently not supported.
				default:
					return nil, errors.New("invalid arguments supplied to `time`")
				}
			},
		}

		ns.AddMethodMapping(ctx.AsTime,
			nil,
			[][2]string{
				{`{{ (time "2015-01-21").Year }}`, `2015`},
			},
		)

		ns.AddMethodMapping(ctx.Duration,
			[]string{"duration"},
			[][2]string{
				{`{{ mul 60 60 | duration "second" }}`, `1h0m0s`},
			},
		)

View on GitHub (pinned to 52c9bd7908)