{"record":{"id":"7d8d5de326e5f25c","repo":"Humanizr/Humanizer","slug":"timeunit-must-be-second-minute-or-hour","errorCode":null,"errorMessage":"timeUnit must be Second, Minute, or Hour","messagePattern":"timeUnit must be Second, Minute, or Hour","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/Bytes/ByteRate.cs","lineNumber":46,"sourceCode":"    /// </summary>\n    /// <param name=\"timeUnit\">Unit of time to calculate rate for (defaults is per second)</param>\n    public string Humanize(TimeUnit timeUnit = TimeUnit.Second) =>\n        Humanize(null, timeUnit);\n\n    /// <summary>\n    /// Calculate rate for the quantity of bytes and interval defined by this instance\n    /// </summary>\n    /// <param name=\"timeUnit\">Unit of time to calculate rate for (defaults is per second)</param>\n    /// <param name=\"format\">The string format to use for the number of bytes</param>\n    /// <param name=\"culture\">Culture to use. If null, current thread's culture is used.</param>\n    public string Humanize(string? format, TimeUnit timeUnit = TimeUnit.Second, CultureInfo? culture = null)\n    {\n        var displayInterval = timeUnit switch\n        {\n            TimeUnit.Second => TimeSpan.FromSeconds(1),\n            TimeUnit.Minute => TimeSpan.FromMinutes(1),\n            TimeUnit.Hour => TimeSpan.FromHours(1),\n            _ => throw new NotSupportedException(\"timeUnit must be Second, Minute, or Hour\"),\n        };\n        return new ByteSize(Size.Bytes / Interval.TotalSeconds * displayInterval.TotalSeconds)\n            .Humanize(format, culture) + '/' + timeUnit.ToSymbol(culture);\n    }\n\n    /// <summary>\n    /// Calculates and humanizes this rate using an explicitly selected byte-size unit system.\n    /// </summary>\n    /// <param name=\"unitSystem\">The byte-size unit system to use.</param>\n    /// <param name=\"format\">\n    /// The numeric format and optional byte-size unit token. For <see cref=\"ByteSizeUnitSystem.DecimalSi\"/> and\n    /// <see cref=\"ByteSizeUnitSystem.BinaryIec\"/>, SI/IEC-prefixed unit tokens are matched case-insensitively,\n    /// while <c>b</c> and <c>B</c> remain case-sensitive; output uses canonical symbol casing.\n    /// <see cref=\"ByteSizeUnitSystem.Legacy\"/> preserves established matching behavior.\n    /// </param>\n    /// <param name=\"timeUnit\">The time unit to use for the displayed rate.</param>\n    /// <param name=\"culture\">The culture used to format the numeric value, byte-size unit, and time-unit symbol.</param>\n    /// <returns>The humanized rate.</returns>","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/Bytes/ByteRate.cs#L28-L64","documentation":"Thrown by ByteRate.Humanize(string?, TimeUnit, CultureInfo?) when the timeUnit argument is not TimeUnit.Second, TimeUnit.Minute, or TimeUnit.Hour. The method computes a display interval from the TimeUnit via a switch expression; the default arm throws NotSupportedException because no other TimeUnit (Day, Week, etc.) has a defined byte-rate display interval.","triggerScenarios":"Calling byteRate.Humanize(format, timeUnit) where timeUnit is TimeUnit.Day, TimeUnit.Week, TimeUnit.Month, TimeUnit.Year, or any other TimeUnit enum value outside the three supported ones.","commonSituations":"A developer iterates over TimeUnit enum values and passes each to Humanize without filtering. Or a caller derives the TimeUnit from user input or configuration without constraining it to the three supported values.","solutions":["Constrain the timeUnit argument to Second, Minute, or Hour before calling Humanize.","If you need a different time unit, compute the rate manually using ByteRate.Size and Interval rather than relying on Humanize's timeUnit switch.","Validate user-supplied TimeUnit input against the supported subset before passing it to Humanize."],"exampleFix":"// before\nvar rate = byteRate.Humanize(null, TimeUnit.Day);\n\n// after\nvar rate = byteRate.Humanize(null, TimeUnit.Second);","handlingStrategy":"validation","validationCode":"if (timeUnit is not (TimeUnit.Second or TimeUnit.Minute or TimeUnit.Hour))\n    throw new ArgumentOutOfRangeException(nameof(timeUnit), \"Must be Second, Minute, or Hour\");\nvar rate = byteRate.Humanize(format, timeUnit, culture);","typeGuard":"static bool IsValidByteRateTimeUnit(TimeUnit unit) =>\n    unit is TimeUnit.Second or TimeUnit.Minute or TimeUnit.Hour;","tryCatchPattern":null,"preventionTips":["Constrain TimeUnit to Second, Minute, or Hour before calling ByteRate.Humanize.","If deriving TimeUnit from user input, validate against the supported subset at the API boundary.","Document the three supported TimeUnit values at the call site."],"tags":["runtime","byte-rate","not-supported","time-unit","validation"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}