Skip to content

Commit

Permalink
Japan(JP, +81): Add support to national carrier code 003768 and 000[2…
Browse files Browse the repository at this point in the history
…59] XXX XXX short codes.
  • Loading branch information
mandlil authored Aug 4, 2023
1 parent ddce5ce commit 1d81d0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -930,9 +930,11 @@ public void testFormatByPattern() {
assertEquals("+1 (650) 253-0000", phoneUtil.formatByPattern(US_NUMBER,
PhoneNumberFormat.INTERNATIONAL,
newNumberFormats));
assertEquals("tel:+1-650-253-0000", phoneUtil.formatByPattern(US_NUMBER,
PhoneNumberFormat.RFC3966,
newNumberFormats));
PhoneNumber usNumber2 =
PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6507129823L).build();
assertEquals(
"tel:+1-650-712-9823",
phoneUtil.formatByPattern(usNumber2, PhoneNumberFormat.RFC3966, newNumberFormats));

// $NP is set to '1' for the US. Here we check that for other NANPA countries the US rules are
// followed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
public abstract class NumberingScheme {
// Bitmask for [1-9] (bits 1..9 set, bit 0 clear).
private static final int NOT_ZERO_MASK = 0x3FE;
private static final String JAPAN_COUNTRY_CODE = "81";

/** Top level information about a numbering scheme. */
@AutoValue
Expand Down Expand Up @@ -416,9 +417,15 @@ private static ImmutableMap<String, FormatSpec> checkFormatConsistency(
|| spec.carrier().map(FormatTemplate::hasNationalPrefix).orElse(false);
nationalPrefixSometimesOptional |= spec.nationalPrefixOptional();
}
checkMetadata(attributes.getCarrierPrefixes().isEmpty() || carrierTemplatesExist,
"[%s] carrier prefixes exist but no formats have carrier templates: %s",
cc, formats.values());
// Only if the present region is not JP do this check as in Japan we are not capturing domestic
// carrier codes, please check cl/529339300 for more details.
if (!cc.toString().equals(JAPAN_COUNTRY_CODE)) {
checkMetadata(
attributes.getCarrierPrefixes().isEmpty() || carrierTemplatesExist,
"[%s] carrier prefixes exist but no formats have carrier templates: %s",
cc,
formats.values());
}
checkMetadata(!attributes.getNationalPrefixes().isEmpty() || !nationalPrefixExistsForFormatting,
"[%s] if no national prefix exists, it cannot be specified in any format template: %s",
cc, formats.values());
Expand Down

0 comments on commit 1d81d0e

Please sign in to comment.