diff --git a/UnitsNet.Tests/CustomCode/LengthTests.FeetInches.cs b/UnitsNet.Tests/CustomCode/LengthTests.FeetInches.cs index 3f30a68660..f2502153d5 100644 --- a/UnitsNet.Tests/CustomCode/LengthTests.FeetInches.cs +++ b/UnitsNet.Tests/CustomCode/LengthTests.FeetInches.cs @@ -41,6 +41,17 @@ public void FeetInchesRoundTrip() [InlineData("1′1″", 1.08333333)] // Without space [InlineData("1 ft 1 in", 1.08333333)] [InlineData("1ft 1in", 1.08333333)] + [InlineData("-1'", -1)] // Feet only + [InlineData("-1′", -1)] // Feet only + [InlineData("-1\"", -0.08333333)] // Inches only + [InlineData("-1″", -0.08333333)] // Inches only + [InlineData("-1' 1\"", -1.08333333)] // Normal form + [InlineData("-1′ 1″", -1.08333333)] // Normal form + [InlineData(" -1′ 1″ ", -1.08333333)] // Normal form, requires trimming + [InlineData("-1'1\"", -1.08333333)] // Without space + [InlineData("-1′1″", -1.08333333)] // Without space + [InlineData("-1 ft 1 in", -1.08333333)] + [InlineData("-1ft 1in", -1.08333333)] public void TryParseFeetInches(string str, double expectedFeet) { Assert.True(Length.TryParseFeetInches(str, out Length result)); diff --git a/UnitsNet/CustomCode/Quantities/Length.extra.cs b/UnitsNet/CustomCode/Quantities/Length.extra.cs index 9e0b0db008..50e6a8f296 100644 --- a/UnitsNet/CustomCode/Quantities/Length.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Length.extra.cs @@ -98,7 +98,7 @@ public static bool TryParseFeetInches([CanBeNull] string str, out Length result, if (TryParse(feetGroup.Value, formatProvider, out Length feet) && TryParse(inchesGroup.Value, formatProvider, out Length inches)) { - result = feet + inches; + result = feet.Value >= 0 ? feet + inches : feet - inches; return true; }