{"record":{"id":"aad8490372d44c10","repo":"Humanizr/Humanizer","slug":"specified-argument-was-out-of-the-range-of-valid-v-aad849","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'seconds')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'seconds'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/Localisation/Formatters/DefaultFormatter.cs","lineNumber":78,"sourceCode":"    /// <inheritdoc/>\n    public virtual string TimeSpanHumanize(TimeUnit timeUnit, int unit, bool toWords = false) =>\n        TryFormatTimeSpanFromPhraseTable(timeUnit, unit, toWords, out var result)\n            ? result\n            : throw new InvalidOperationException($\"Missing generated time-span phrase for '{Culture.Name}' and unit '{timeUnit}'.\");\n\n    /// <summary>\n    /// Returns the localized representation of a non-negative seconds value.\n    /// </summary>\n    /// <param name=\"seconds\">The non-negative seconds value to format.</param>\n    /// <param name=\"toSymbols\">Whether the seconds unit is rendered as a symbol.</param>\n    /// <returns>The localized seconds value.</returns>\n    public virtual string TimeSpanHumanizeWithFractionalSeconds(decimal seconds, bool toSymbols)\n    {\n#if NET8_0_OR_GREATER\n        ArgumentOutOfRangeException.ThrowIfNegative(seconds);\n#else\n        if (seconds < 0)\n            throw new ArgumentOutOfRangeException(nameof(seconds));\n#endif\n\n        var visibleSeconds = decimal.Parse(\n            seconds.ToString(\"0.#######\", CultureInfo.InvariantCulture),\n            CultureInfo.InvariantCulture);\n        var countValue = visibleSeconds.ToString(\n            \"0.#######\",\n            LocaleNumberFormattingOverrides.GetFormattingNumberFormat(Culture));\n\n        var category = ValidateFractionalSecondGrammar(visibleSeconds, toSymbols);\n\n        if (toSymbols)\n        {\n            return string.Concat(countValue, TimeUnitHumanize(TimeUnit.Second));\n        }\n\n        if (!phraseTable.TryGetTimeSpanPhrase(TimeUnit.Second, out var phrase) ||\n            phrase.Multiple is not { } multiple)","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/Localisation/Formatters/DefaultFormatter.cs#L60-L96","documentation":"Thrown by DefaultFormatter.TimeSpanHumanizeWithFractionalSeconds when the seconds value is negative. The method formats a non-negative fractional-seconds count, so a negative value is invalid; zero is allowed. On .NET 8+ it uses ArgumentOutOfRangeException.ThrowIfNegative; otherwise a manual throw. The parameter is named 'seconds'.","triggerScenarios":"Calling formatter.TimeSpanHumanizeWithFractionalSeconds(-0.5m, false); passing a computed seconds value from a negative TimeSpan without taking the absolute value; feeding a sensor/delta value that can be negative into the formatter directly.","commonSituations":"Neglecting to take TimeSpan.TotalSeconds absolute value before formatting a duration; passing a signed difference (e.g. now - other) where the sign was not resolved; reusing a 'seconds remaining' counter that can go negative on overshoot.","solutions":["Pass Math.Abs(seconds) when you only care about the magnitude of the fractional seconds.","Validate the sign at the source: if a negative value means 'in the past', branch and format the absolute value with a contextual prefix.","Guard with a precondition: if (seconds < 0) throw or default before calling."],"exampleFix":"// before\nvar text = formatter.TimeSpanHumanizeWithFractionalSeconds((decimal)ts.TotalSeconds, true);\n\n// after\nvar secs = Math.Abs((decimal)ts.TotalSeconds);\nvar text = formatter.TimeSpanHumanizeWithFractionalSeconds(secs, true);","handlingStrategy":"validation","validationCode":"if (seconds < 0)\n    throw new ArgumentOutOfRangeException(nameof(seconds), \"Must be non-negative.\");\nvar text = formatter.TimeSpanHumanizeWithFractionalSeconds(seconds, toSymbols);","typeGuard":"static bool IsValidSeconds(decimal s) => s >= 0;","tryCatchPattern":"try { return formatter.TimeSpanHumanizeWithFractionalSeconds(seconds, toSymbols); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"seconds\")\n{ return formatter.TimeSpanHumanizeWithFractionalSeconds(Math.Abs(seconds), toSymbols); }","preventionTips":["Take Math.Abs of TimeSpan.TotalSeconds before formatting durations.","Branch on sign to label 'past' vs 'future' rather than passing negatives.","Guard sensor/delta inputs at the source."],"tags":["timespan","formatter","argument-validation","argument-out-of-range"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}