Humanizr/Humanizer · error · InvalidOperationException

Ordinal date profile '{profile.ProfileName}' has calendar mo

Error message

Ordinal date profile '{profile.ProfileName}' has calendar month overrides but pattern does not contain an unescaped MMMM specifier.

What it means

Thrown during source generation by CreatePatternExpression when an ordinal-date profile has calendar month overrides (months or hijriMonths defined) but the pattern string contains zero unescaped MMMM specifiers. The generator needs exactly one MMMM token to inject the overridden month name; without it, the overrides are useless and the generator rejects the configuration.

Source

Thrown at src/Humanizer.SourceGenerators/Generators/ProfileCatalogs/OrdinalDateProfileCatalogInput.cs:202

            var pattern = GetRequiredString(profile.Root, "pattern");
            var hasGregorianMonths = profile.Months.Length > 0;
            var hasHijriMonths = profile.HijriMonths.Length > 0;
            var hasAnyMonthOverride = hasGregorianMonths || hasHijriMonths;

            if (hasAnyMonthOverride && ContainsAbbreviatedMonth(pattern))
            {
                throw new InvalidOperationException(
                    $"Ordinal date profile '{profile.ProfileName}' uses MMM (abbreviated month) " +
                    "which is not supported when calendar month overrides are active. " +
                    "Only MMMM (full month name) substitution is supported.");
            }

            if (hasAnyMonthOverride)
            {
                var mmmmCount = CountUnescapedFullMonth(pattern);
                if (mmmmCount == 0)
                {
                    throw new InvalidOperationException(
                        $"Ordinal date profile '{profile.ProfileName}' has calendar month overrides " +
                        "but pattern does not contain an unescaped MMMM specifier.");
                }

                if (mmmmCount > 1)
                {
                    throw new InvalidOperationException(
                        $"Ordinal date profile '{profile.ProfileName}' has calendar month overrides " +
                        "but pattern contains multiple unescaped MMMM specifiers. Only one is supported.");
                }
            }

            var calendarMode = GetOptionalString(profile.Root, "calendarMode");
            var hasCalendarMode = calendarMode is not null && !string.Equals(calendarMode, "Gregorian", StringComparison.OrdinalIgnoreCase);

            var expr = "new " + converterTypeName + "(new OrdinalDatePattern(" +
                       QuoteLiteral(pattern) +
                       ", OrdinalDateDayMode." +

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Add an unescaped MMMM specifier to the pattern string so the generator can inject the overridden month name.
  2. Remove the calendar.months and calendar.hijriMonths overrides if the pattern intentionally does not display month names.
  3. Check for accidentally escaped MMMM — ensure it is not inside single quotes in the .NET format string.

Example fix

# locale YAML — before (month overrides but no MMMM in pattern)
ordinalDate:
  engine: pattern
  pattern: "dd yyyy"
calendar:
  months:
    - January
    - February

# after — add MMMM to pattern
ordinalDate:
  engine: pattern
  pattern: "dd MMMM yyyy"
calendar:
  months:
    - January
    - February
Defensive patterns

Strategy: validation

Validate before calling

// Before building, if a locale YAML has calendar month overrides for
// ordinal dates, verify the pattern contains exactly one unescaped MMMM.
// An escaped MMMM (inside single quotes) does not count.

Prevention

When it happens

Trigger: A locale YAML defines calendar.months or calendar.hijriMonths but the ordinal-date pattern has no MMMM token — for example the pattern is 'dd yyyy' (day and year only) or all month references are escaped inside string literals.

Common situations: A maintainer adds month overrides but the pattern was designed for a locale that doesn't display month names, or the MMMM was accidentally removed or escaped during pattern editing.

Related errors


AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13). Data as JSON: /api/errors/62fc06727408b86e. Report an issue: GitHub.