{"record":{"id":"72ce5d644c54a45a","repo":"Humanizr/Humanizer","slug":"value-is-not-a-supported-timespan-format","errorCode":null,"errorMessage":"Value is not a supported TimeSpan format.","messagePattern":"Value is not a supported TimeSpan format\\.","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/TimeSpanDehumanizeExtensions.cs","lineNumber":33,"sourceCode":"    /// </summary>\n    /// <param name=\"input\">The duration text to parse.</param>\n    /// <returns>The parsed duration.</returns>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"input\"/> is null.</exception>\n    /// <exception cref=\"FormatException\">Thrown when <paramref name=\"input\"/> is not a supported duration.</exception>\n    /// <remarks>\n    /// Compact tokens are culture-invariant, may be separated by whitespace, and may have one leading sign.\n    /// Units may repeat and appear in any order; their values are added. Each token must resolve to whole ticks.\n    /// A week is seven days.\n    /// Colon-separated values use the standard invariant <see cref=\"TimeSpan\"/> interpretation.\n    /// </remarks>\n    public static TimeSpan DehumanizeTimeSpan(this string input)\n    {\n        ArgumentNullException.ThrowIfNull(input);\n\n        if (TryDehumanizeTimeSpan(input, out var result))\n            return result;\n\n        throw new FormatException(\"Value is not a supported TimeSpan format.\");\n    }\n\n    /// <summary>\n    /// Tries to parse a standard invariant <see cref=\"TimeSpan\"/> value or compact duration tokens using\n    /// <c>ms</c>, <c>s</c>, <c>m</c>, <c>h</c>, <c>d</c>, and <c>w</c>.\n    /// </summary>\n    /// <param name=\"input\">The duration text to parse.</param>\n    /// <param name=\"result\">The parsed duration, or <see cref=\"TimeSpan.Zero\"/> when parsing fails.</param>\n    /// <returns><see langword=\"true\"/> when parsing succeeds; otherwise, <see langword=\"false\"/>.</returns>\n    /// <remarks>\n    /// Compact tokens are culture-invariant, may be separated by whitespace, and may have one leading sign.\n    /// Units may repeat and appear in any order; their values are added. Each token must resolve to whole ticks.\n    /// A week is seven days.\n    /// Colon-separated values use the standard invariant <see cref=\"TimeSpan\"/> interpretation.\n    /// </remarks>\n    public static bool TryDehumanizeTimeSpan(this string? input, out TimeSpan result)\n    {\n        result = default;","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/TimeSpanDehumanizeExtensions.cs#L15-L51","documentation":"Thrown by DehumanizeTimeSpan when the input string cannot be parsed as either a standard invariant TimeSpan (e.g. \"1:30:00\") or compact duration tokens using ms, s, m, h, d, w (e.g. \"1h30m\"). The method first tries TryDehumanizeTimeSpan and throws FormatException when it returns false.","triggerScenarios":"Calling \"hello\".DehumanizeTimeSpan(), \"1y\".DehumanizeTimeSpan() (year is not a token), or \"\".DehumanizeTimeSpan(). Also fires for tokens that don't resolve to whole ticks.","commonSituations":"Parsing localized duration words (e.g. \"one hour\") instead of compact tokens. Using unsupported unit abbreviations. Feeding user-entered free-text into DehumanizeTimeSpan without validation.","solutions":["Use TryDehumanizeTimeSpan instead to get a boolean result without throwing.","Validate the input contains only supported tokens (ms, s, m, h, d, w) or a colon-separated TimeSpan.","Provide a fallback TimeSpan when parsing fails."],"exampleFix":"// before\nvar ts = input.DehumanizeTimeSpan();\n\n// after\nif (!input.TryDehumanizeTimeSpan(out var ts))\n    ts = TimeSpan.Zero;","handlingStrategy":"validation","validationCode":"static bool TrySafeDehumanize(string input, out TimeSpan result) =>\n    input.TryDehumanizeTimeSpan(out result);","typeGuard":null,"tryCatchPattern":"if (!input.TryDehumanizeTimeSpan(out var ts))\n{\n    // handle invalid input\n}","preventionTips":["Prefer TryDehumanizeTimeSpan over DehumanizeTimeSpan for untrusted input.","Whitelist supported unit tokens (ms, s, m, h, d, w) in your input parser.","Test with unsupported units like 'y' and free-text."],"tags":["timespan","dehumanize","input-parsing","format"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}