Skip to content

Commit

Permalink
Japan(JP, +81): Add support to national carrier code 003768 and short…
Browse files Browse the repository at this point in the history
… code prefix 000[259]. (#3142)

* Japan(JP, +81): Add support to national carrier code 003768 and 000[259] XXX XXX short codes.

* updating the testFormatByPattern()

* Update NumberingScheme.java
  • Loading branch information
mandlil authored Aug 7, 2023
1 parent ddce5ce commit 263caa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -930,9 +930,10 @@ 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 = new PhoneNumber().setCountryCode(1).setNationalNumber(6507129823L);
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.
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 263caa9

Please sign in to comment.