Skip to content

Fix for negative feet/inch parsing #674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions UnitsNet.Tests/CustomCode/LengthTests.FeetInches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion UnitsNet/CustomCode/Quantities/Length.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down