diff --git a/src/Humanizer.Tests.Shared/HeadingTests.cs b/src/Humanizer.Tests.Shared/HeadingTests.cs index 3ba6b0ad5..55d3775c2 100644 --- a/src/Humanizer.Tests.Shared/HeadingTests.cs +++ b/src/Humanizer.Tests.Shared/HeadingTests.cs @@ -1,4 +1,6 @@ -using Xunit; +using System.Globalization; + +using Xunit; namespace Humanizer.Tests { @@ -189,5 +191,14 @@ public void FromHeadingArrow_Also_Works_With_Strings(string heading, double expe { Assert.Equal(expected, heading.FromHeadingArrow()); } + + [InlineData("NNW", "en-US", 337.5)] + [InlineData("ØNØ", "da", 67.5)] + [InlineData("O", "de-DE", 90.0)] + [Theory] + public void FromShortHeading_CanSpecifyCultureExplicitly(string heading, string culture, double expected) + { + Assert.Equal(expected, heading.FromAbbreviatedHeading(new CultureInfo(culture))); + } } } diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt index 91e266757..7b7e1d0a8 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt @@ -126,6 +126,7 @@ namespace Humanizer } public class static HeadingExtensions { + public static double FromAbbreviatedHeading(this string heading) { } public static double FromAbbreviatedHeading(this string heading, System.Globalization.CultureInfo culture = null) { } public static double FromHeadingArrow(this char heading) { } public static double FromHeadingArrow(this string heading) { } diff --git a/src/Humanizer/HeadingExtensions.cs b/src/Humanizer/HeadingExtensions.cs index 760a4bb52..5a1621b32 100644 --- a/src/Humanizer/HeadingExtensions.cs +++ b/src/Humanizer/HeadingExtensions.cs @@ -68,6 +68,15 @@ public static char ToHeadingArrow(this double heading) return headingArrows[val % 8]; } + /// + /// Returns a heading based on the short textual representation of the heading. + /// + /// The heading. -1 if the heading could not be parsed. + public static double FromAbbreviatedHeading(this string heading) + { + return heading.FromAbbreviatedHeading(null); + } + /// /// Returns a heading based on the short textual representation of the heading. ///