Skip to content

Commit

Permalink
refactor: Re-add FromAbbreviatedHeading overload without culture
Browse files Browse the repository at this point in the history
  • Loading branch information
hangy committed Aug 23, 2021
1 parent 295b731 commit 9d48857
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Humanizer.Tests.Shared/HeadingTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Xunit;
using System.Globalization;

using Xunit;

namespace Humanizer.Tests
{
Expand Down Expand Up @@ -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)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
Expand Down
9 changes: 9 additions & 0 deletions src/Humanizer/HeadingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public static char ToHeadingArrow(this double heading)
return headingArrows[val % 8];
}

/// <summary>
/// Returns a heading based on the short textual representation of the heading.
/// </summary>
/// <returns>The heading. -1 if the heading could not be parsed.</returns>
public static double FromAbbreviatedHeading(this string heading)
{
return heading.FromAbbreviatedHeading(null);
}

/// <summary>
/// Returns a heading based on the short textual representation of the heading.
/// </summary>
Expand Down

0 comments on commit 9d48857

Please sign in to comment.