gohugoio/hugo · error

failed to parse clock: %s

Error message

failed to parse clock: %s

What it means

Hugo's `clock` setting (internal config, set via the `--clock` CLI flag) freezes the build's notion of "now" for testing time-dependent features like future-dated content. The value must parse as RFC 3339; anything else fails config compilation with this error.

Source

Thrown at config/allconfig/allconfig.go:393

				return fmt.Errorf("failed to compile ignoreFiles pattern %q: %s", pattern, err)
			}
		}
		ignoreFile = func(s string) bool {
			for _, r := range regexps {
				if r.MatchString(s) {
					return true
				}
			}
			return false
		}
	}

	var clock time.Time
	if c.Internal.Clock != "" {
		var err error
		clock, err = time.Parse(time.RFC3339, c.Internal.Clock)
		if err != nil {
			return fmt.Errorf("failed to parse clock: %s", err)
		}
	}

	httpCache, err := c.HTTPCache.Compile()
	if err != nil {
		return err
	}

	// Legacy language values.
	if c.LanguageCode != "" {
		if !c.isLanguageClone {
			hugo.DeprecateWithLogger("project config key languageCode", "Use locale instead.", "v0.158.0", logger.Logger())
		}
		if c.Locale == "" {
			c.Locale = c.LanguageCode
		}
		c.LanguageCode = ""
	}

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Use full RFC 3339 format: `hugo --clock 2026-07-31T00:00:00Z`.
  2. Include a timezone offset if not UTC: `2026-07-31T00:00:00-05:00`.
  3. Drop the flag entirely if you just want the real current time.

Example fix

# before
hugo --clock 2026-07-31
# after
hugo --clock 2026-07-31T00:00:00Z
Defensive patterns

Strategy: validation

Validate before calling

if clockStr != "" {
    if _, err := time.Parse(time.RFC3339, clockStr); err != nil {
        return fmt.Errorf("clock %q must be RFC3339, e.g. 2026-07-31T00:00:00Z", clockStr)
    }
}

Prevention

When it happens

Trigger: Running `hugo --clock 2026-07-31` or setting the clock to any non-RFC3339 string — missing time portion, missing timezone offset, or a locale-style date like `07/31/2026`.

Common situations: Users passing date-only values to `--clock` in CI to test publish dates, or omitting the `Z`/offset suffix; RFC 3339 requires the full `2026-07-31T15:00:00Z` shape.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/87176f524deb8a2f.json. Report an issue: GitHub ↗.