Humanizr/Humanizer · error · InvalidOperationException

The configured ITimeSpanHumanizeStrategy does not support fr

Error message

The configured ITimeSpanHumanizeStrategy does not support fractional seconds. Implement IFractionalTimeSpanHumanizeStrategy to handle genuinely fractional results.

What it means

Thrown by HumanizeWithFractionalSecondsCore when the configured strategy does not implement IFractionalTimeSpanHumanizeStrategy AND the rounded TimeSpan still has visible fractional seconds. Humanizer first tries to round the value to remove fractional seconds; only if they persist does it throw, because the output would silently lose precision.

Source

Thrown at src/Humanizer/TimeSpanHumanizeExtensions.cs:321

        if (strategy is IFractionalTimeSpanHumanizeStrategy fractionalStrategy)
        {
            return fractionalStrategy.HumanizeWithFractionalSeconds(
                timeSpan,
                precision,
                countEmptyUnits,
                culture,
                maxUnit,
                collectionSeparator,
                maxFractionalDigits,
                roundingMode,
                toSymbols);
        }

        var roundedTimeSpan = RoundToFractionalSecondPrecision(timeSpan, maxFractionalDigits, roundingMode);
        if (HasVisibleFractionalSeconds(roundedTimeSpan, precision, countEmptyUnits, maxUnit))
        {
            throw new InvalidOperationException(
                $"The configured {nameof(ITimeSpanHumanizeStrategy)} does not support fractional seconds. " +
                $"Implement {nameof(IFractionalTimeSpanHumanizeStrategy)} to handle genuinely fractional results.");
        }

        return strategy.Humanize(
            roundedTimeSpan.ToTimeSpan(),
            precision,
            countEmptyUnits,
            culture,
            maxUnit,
            TimeUnit.Second,
            collectionSeparator,
            false,
            toSymbols);
    }

    internal static void ValidateFractionalSecondArguments(
        int maxFractionalDigits,

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Make your custom strategy implement IFractionalTimeSpanHumanizeStrategy.
  2. Use the built-in DefaultTimeSpanHumanizeStrategy which supports fractional seconds.
  3. Round the TimeSpan to whole seconds before humanizing if fractional output isn't needed.

Example fix

// before
Configurator.TimeSpanHumanizeStrategy = new MyBasicStrategy();
var s = ts.HumanizeWithFractionalSeconds(3, 3, MidpointRounding.ToEven);

// after
public class MyStrategy : ITimeSpanHumanizeStrategy, IFractionalTimeSpanHumanizeStrategy
{
    // implement HumanizeWithFractionalSeconds(...)
}
Defensive patterns

Strategy: type-guard

Validate before calling

static bool StrategySupportsFractional(ITimeSpanHumanizeStrategy strategy) =>
    strategy is IFractionalTimeSpanHumanizeStrategy;

Type guard

static bool CanHumanizeFractional(ITimeSpanHumanizeStrategy strategy) =>
    strategy is IFractionalTimeSpanHumanizeStrategy ||
    strategy.GetType() == typeof(DefaultTimeSpanHumanizeStrategy);

Prevention

When it happens

Trigger: Calling a fractional-seconds humanize method (e.g. HumanizeWithFractionalSeconds) with a custom ITimeSpanHumanizeStrategy that doesn't implement IFractionalTimeSpanHumanizeStrategy, on a TimeSpan whose seconds component has a non-zero fractional part after rounding.

Common situations: Using a custom strategy for word-based output but attempting fractional seconds. The TimeSpan has sub-second ticks that survive rounding to the requested precision. Strategy was written before fractional-seconds support was added.

Related errors


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