Skip to content

Commit

Permalink
Closes #600
Browse files Browse the repository at this point in the history
Some Australia non-geographic numbers don’t require a trunk prefix
  • Loading branch information
TrevorPilley committed Mar 20, 2024
1 parent 5b6ce6b commit 66354c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Expand Up @@ -11,8 +11,15 @@ private AUPhoneNumberFormatProvider()

internal static PhoneNumberFormatProvider Instance { get; } = new AUPhoneNumberFormatProvider();

protected override string ProvideFormat(PhoneNumber phoneNumber, bool international) =>
phoneNumber.NationalSignificantNumber.Length switch
protected override string ProvideFormat(PhoneNumber phoneNumber, bool international)
{
if (phoneNumber is NonGeographicPhoneNumber nonGeographicPhoneNumber &&
nonGeographicPhoneNumber.IsFreephone)
{
return "#### ### ###";
}

return phoneNumber.NationalSignificantNumber.Length switch
{
9 => phoneNumber.Kind switch
{
Expand All @@ -21,4 +28,5 @@ phoneNumber.NationalSignificantNumber.Length switch
},
_ => base.ProvideFormat(phoneNumber, international),
};
}
}
3 changes: 3 additions & 0 deletions test/PhoneNumbers.Tests/PhoneNumber_ToString_Oceania_Tests.cs
Expand Up @@ -12,10 +12,13 @@ public class PhoneNumber_ToString_Oceania_Tests
[Theory]
[InlineData("+61399636800", "E.123", "+61 3 9963 6800")]
[InlineData("+61436986301", "E.123", "+61 436 986 301")]
[InlineData("+611800900090", "E.123", "+61 1800 900 090")]
[InlineData("+61399636800", "N", "(03) 9963 6800")]
[InlineData("+61436986301", "N", "0436 986 301")]
[InlineData("+611800900090", "N", "1800 900 090")]
[InlineData("+61399636800", "RFC3966", "tel:+61-3-9963-6800")]
[InlineData("+61436986301", "RFC3966", "tel:+61-436-986-301")]
[InlineData("+611800900090", "RFC3966", "tel:+61-1800-900-090")]
public void Australia_Numbers(string input, string format, string expected) =>
Assert.Equal(expected, PhoneNumber.Parse(input).ToString(format));

Expand Down

0 comments on commit 66354c8

Please sign in to comment.