Skip to content

Commit 7baab0c

Browse files
authored
Area code information lost for all MX numbers
1 parent 408395c commit 7baab0c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

csharp/PhoneNumbers.Test/TestPhoneNumberUtil.cs

+3
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ public void TestGetLengthOfGeographicalAreaCode()
296296
// Italian numbers - there is no national prefix, but it still has an area code.
297297
Assert.Equal(2, phoneUtil.GetLengthOfGeographicalAreaCode(ITNumber));
298298

299+
// Mexico numbers - there is no national prefix, but it still has an area code.
300+
Assert.Equal(2, phoneUtil.GetLengthOfGeographicalAreaCode(MXNumber1));
301+
299302
// Google Singapore. Singapore has no area code and no national prefix.
300303
Assert.Equal(0, phoneUtil.GetLengthOfGeographicalAreaCode(SGNumber));
301304

csharp/PhoneNumbers/PhoneNumberUtil.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public partial class PhoneNumberUtil
7373
private static bool IsGeoMobileCountryWithoutMobileAreaCode(int countryCallingCode)
7474
=> countryCallingCode is 86; // China
7575

76+
// Set of country codes that doesn't have national prefix, but it has area codes.
77+
private static bool IsCountryWithoutNationalPrefixWithAreaCodes(int countryCallingCode)
78+
=> countryCallingCode is 52; // Mexico
79+
7680
// Set of country calling codes that have geographically assigned mobile numbers. This may not be
7781
// complete; we add calling codes case by case, as we find geographical mobile numbers or hear
7882
// from user reports. Note that countries like the US, where we can't distinguish between
@@ -662,14 +666,18 @@ public int GetLengthOfGeographicalAreaCode(PhoneNumber number)
662666
var regionCode = GetRegionCodeForNumber(number);
663667
if (!IsValidRegionCode(regionCode))
664668
return 0;
669+
670+
var type = GetNumberType(number);
671+
var countryCallingCode = number.CountryCode;
665672
var metadata = GetMetadataForRegion(regionCode);
666673
// If a country doesn't use a national prefix, and this number doesn't have an Italian leading
667674
// zero, we assume it is a closed dialling plan with no area codes.
668-
if (!metadata.HasNationalPrefix && !number.HasNumberOfLeadingZeros)
675+
// Note:this is our general assumption, but there are exceptions which are tracked in
676+
// COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES.
677+
if (!metadata.HasNationalPrefix && !number.HasNumberOfLeadingZeros &&
678+
!IsCountryWithoutNationalPrefixWithAreaCodes(countryCallingCode))
669679
return 0;
670680

671-
var type = GetNumberType(number);
672-
var countryCallingCode = number.CountryCode;
673681
if (type == PhoneNumberType.MOBILE
674682
// Note this is a rough heuristic; it doesn't cover Indonesia well, for example, where area
675683
// codes are present for some mobile phones but not for others. We have no better way of

0 commit comments

Comments
 (0)