gohugoio/hugo · error

failed to parse clock

Error message

failed to parse clock: %s

What it means

Returned by CompileConfig when `internal.clock` is set but does not parse as an RFC3339 timestamp. The clock is used to pin `now` deterministically (mainly for testing/reproducible builds). time.Parse(time.RFC3339, c.Internal.Clock) failure wraps the parse error here.

Solutions

  1. Use a strict RFC3339 form: `2006-01-02T15:04:05Z07:00`.
  2. Include the timezone (Z or +HH:MM); bare dates like 2024-01-01 will fail.
  3. Leave internal.clock empty for production builds.

Example fix

// before
[internal]
clock = "2024-01-01"
// after
[internal]
clock = "2024-01-01T00:00:00Z"
Defensive patterns

Strategy: validation

Validate before calling

func validateClock(s string) error {
  if s == "" { return nil }
  if _, err := time.Parse(time.RFC3339, s); err != nil { return fmt.Errorf("clock must be RFC3339, got %q", s) }
  return nil
}

Prevention

When it happens

Trigger: Setting `internal.clock` to anything other than a strict RFC3339 string (e.g. '2024-01-01', 'Jan 2 2024', '2024/01/01', or a unix timestamp).

Common situations: Authors copying a human-readable date into internal.clock, locale-specific date formats, or omitting the required time/timezone components of RFC3339.

Understand the failure class

Related errors


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

Appendix: 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 52c9bd7908)