diff --git a/CHANGELOG.md b/CHANGELOG.md index d259b43be..7b1848298 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,7 @@ - X10D.Unity: Added `WaitForTimeSpanRealtimeNoAlloc` yield instruction ### Changed +- X10D: `TimeSpanParser.TryParse` now accepts a nullable string, and returns false if this input is null or empty - X10D.Unity: Obsolesced `Singleton` ## [3.1.0] diff --git a/X10D/src/Time/TimeSpanParser.cs b/X10D/src/Time/TimeSpanParser.cs index 2839f22db..a6078eebd 100644 --- a/X10D/src/Time/TimeSpanParser.cs +++ b/X10D/src/Time/TimeSpanParser.cs @@ -1,4 +1,6 @@ -namespace X10D.Time; +using System.Diagnostics.CodeAnalysis; + +namespace X10D.Time; /// /// Represents a class which contains a parser which converts into . @@ -54,15 +56,15 @@ public static class TimeSpanParser /// /// When this method returns, contains the parsed result. /// if the parse was successful, otherwise. - /// is . - public static bool TryParse(string value, out TimeSpan result) + public static bool TryParse([NotNullWhen(true)] string? value, out TimeSpan result) { - if (value is null) + result = TimeSpan.Zero; + + if (string.IsNullOrWhiteSpace(value)) { - throw new ArgumentNullException(nameof(value)); + return false; } - result = TimeSpan.Zero; var unitValue = 0; for (var index = 0; index < value.Length; index++)