{"record":{"id":"ea00c5753484e77b","repo":"MudBlazor/MudBlazor","slug":"not-a-valid-date-time-ea00c5","errorCode":null,"errorMessage":"Not a valid date time","messagePattern":"Not a valid date time","errorType":"exception","errorClass":"ConversionException","httpStatus":null,"severity":"error","filePath":"src/MudBlazor/Converters/DefaultConverter.TimeOnly.cs","lineNumber":34,"sourceCode":"        public string Convert(TimeOnly input) => input.ToString(format.Invoke(), culture.Invoke());\n\n        public string? Convert(TimeOnly? input) => input?.ToString(format.Invoke(), culture.Invoke());\n\n        public TimeOnly ConvertBack(string? input)\n        {\n            if (string.IsNullOrEmpty(input))\n            {\n                return default;\n            }\n\n            var currentCulture = culture.Invoke();\n            if (TimeOnly.TryParseExact(input, format.Invoke() ?? currentCulture.DateTimeFormat.ShortDatePattern, currentCulture, DateTimeStyles.None, out var result))\n            {\n                return result;\n            }\n\n            // TODO: Differentiate error message for TimeOnly\n            throw new ConversionException(LanguageResource.Converter_InvalidDateTime);\n        }\n\n        TimeOnly? IReversibleConverter<TimeOnly?, string?>.ConvertBack(string? input)\n        {\n            if (string.IsNullOrEmpty(input))\n            {\n                return null;\n            }\n\n            return ConvertBack(input);\n        }\n    }\n}\n","sourceCodeStart":16,"sourceCodeEnd":48,"githubUrl":"https://github.com/MudBlazor/MudBlazor/blob/bdb3acd5ddc0a563428488e7afef0d99549f7a6c/src/MudBlazor/Converters/DefaultConverter.TimeOnly.cs#L16-L48","documentation":"Thrown by TimeOnlyConverter.ConvertBack when the input is non-empty but TimeOnly.TryParseExact fails. ConversionException key is Converter_InvalidDateTime (a TODO notes TimeOnly does not yet have its own message). Note a latent quirk: when Format() is null the fallback is the culture's ShortDatePattern — a date pattern used to parse a time — which makes null Format very likely to throw. Empty input returns default(TimeOnly).","triggerScenarios":"ConvertBack(\"14:30:00\") when Format is null (falls back to ShortDatePattern and fails); ConvertBack(\"2:30 PM\") when the format is \"HH:mm\"; any time string not exactly matching the configured format.","commonSituations":"Forgetting to set a time Format on the converter/component so it falls back to a date pattern; 12-hour vs 24-hour mismatch; culture whose time patterns differ from what the user types.","solutions":["Always set an explicit time Format (e.g. \"HH:mm\" or \"h:mm tt\") on the component/converter — never rely on the null fallback.","Pre-validate with TimeOnly.TryParseExact(input, format, culture, DateTimeStyles.None, out _).","Catch ConversionException and show the localized message.","Use a MudTimePicker so the value round-trips through the same format."],"exampleFix":"// before\nvar converter = new DefaultConverter<TimeOnly>(); // Format=null -> ShortDatePattern\nvar t = converter.ConvertBack(\"14:30\"); // throws\n\n// after\nvar converter = new DefaultConverter<TimeOnly> { Format = () => \"HH:mm\" };","handlingStrategy":"try-catch","validationCode":"static bool CanParseTimeOnly(string? input, CultureInfo culture, string? format) =>\n    string.IsNullOrEmpty(input) ||\n    TimeOnly.TryParseExact(input, format ?? \"HH:mm\", culture, DateTimeStyles.None, out _);","typeGuard":null,"tryCatchPattern":"try { var t = converter.ConvertBack(input); }\ncatch (ConversionException ex) { ReportUserError(ex.ErrorMessageKey, ex.ErrorMessageArgs); }","preventionTips":["Always set an explicit time Format; never rely on the null->ShortDatePattern fallback.","Use a MudTimePicker so values round-trip through one format.","Match 12/24-hour format to user expectations."],"tags":["converter","timeonly","parsing","user-input","culture"],"backgroundTag":null,"analyzedSha":"bdb3acd5ddc0a563428488e7afef0d99549f7a6c","analyzedAt":"2026-08-13T19:36:54.040Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}