{"record":{"id":"4ec4c16de97b49e2","repo":"Humanizr/Humanizer","slug":"fractional-seconds-support-only-midpoint-rounding","errorCode":null,"errorMessage":"Fractional seconds support only midpoint rounding ToEven and AwayFromZero.","messagePattern":"Fractional seconds support only midpoint rounding ToEven and AwayFromZero\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/TimeSpanHumanizeExtensions.cs","lineNumber":350,"sourceCode":"            TimeUnit.Second,\n            collectionSeparator,\n            false,\n            toSymbols);\n    }\n\n    internal static void ValidateFractionalSecondArguments(\n        int maxFractionalDigits,\n        MidpointRounding roundingMode,\n        TimeUnit maxUnit)\n    {\n        if (maxFractionalDigits is < 0 or > 7)\n        {\n            throw new ArgumentOutOfRangeException(nameof(maxFractionalDigits));\n        }\n\n        if (roundingMode is not (MidpointRounding.ToEven or MidpointRounding.AwayFromZero))\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(roundingMode),\n                roundingMode,\n                \"Fractional seconds support only midpoint rounding ToEven and AwayFromZero.\");\n        }\n\n        if (maxUnit is < TimeUnit.Second or > TimeUnit.Year)\n        {\n            throw new ArgumentOutOfRangeException(nameof(maxUnit));\n        }\n    }\n\n    static RoundedTimeSpan RoundToFractionalSecondPrecision(\n        TimeSpan timeSpan,\n        int maxFractionalDigits,\n        MidpointRounding roundingMode)\n    {\n        var magnitudeTicks = Math.Abs((decimal)timeSpan.Ticks);\n        var quantumTicks = DecimalPowersOfTen[7 - maxFractionalDigits];","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/TimeSpanHumanizeExtensions.cs#L332-L368","documentation":"Thrown by ValidateFractionalSecondArguments when the roundingMode parameter is neither MidpointRounding.ToEven nor MidpointRounding.AwayFromZero. Fractional-second rounding in Humanizer only supports these two deterministic midpoint strategies; others like ToPositiveInfinity or ToZero would produce locale-inconsistent results.","triggerScenarios":"Calling any fractional-seconds humanize method with MidpointRounding.ToNegativeInfinity, ToPositiveInfinity, or ToZero as the roundingMode argument.","commonSituations":"Developer passes a different MidpointRounding value expecting it to work. Copying a rounding mode from a different API. Enum cast from an integer that doesn't map to the two supported values.","solutions":["Use MidpointRounding.AwayFromZero or MidpointRounding.ToEven only.","Validate the rounding mode before the call and default to ToEven if unsupported.","Review the fractional-seconds API documentation for the two supported modes."],"exampleFix":"// before\nvar s = ts.HumanizeWithFractionalSeconds(3, 3, MidpointRounding.ToZero);\n\n// after\nvar mode = roundingMode is MidpointRounding.ToEven or MidpointRounding.AwayFromZero\n    ? roundingMode\n    : MidpointRounding.ToEven;\nvar s = ts.HumanizeWithFractionalSeconds(3, 3, mode);","handlingStrategy":"validation","validationCode":"static bool IsValidRoundingMode(MidpointRounding mode) =>\n    mode is MidpointRounding.ToEven or MidpointRounding.AwayFromZero;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict rounding mode selection to ToEven and AwayFromZero in your UI.","Validate MidpointRounding before the call.","Default to MidpointRounding.ToEven when in doubt."],"tags":["timespan","fractional-seconds","argument-validation","range-check"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}