Skip to content

Commit

Permalink
Update formatForMobileDialling() for Columbia 03
Browse files Browse the repository at this point in the history
The national code 03 is deprecated after Colombia renumbering

Mirrors google/libphonenumber#2786
  • Loading branch information
giggsey committed Jul 11, 2022
1 parent b072e24 commit caed0f1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion METADATA-VERSION.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# It can be a commit, branch or tag of the https://github.com/google/libphonenumber project
#
# For more information, look at the phing tasks in build.xml
v8.12.50
99a44a6ab50ccbd7654de6b6c803bd81977e9e99
4 changes: 4 additions & 0 deletions src/CountryCodeToRegionCodeMapForTesting.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class CountryCodeToRegionCodeMapForTesting {
array (
0 => 'BR',
),
57 =>
array (
0 => 'CO',
),
61 =>
array (
0 => 'AU',
Expand Down
12 changes: 1 addition & 11 deletions src/PhoneNumberUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ class PhoneNumberUtil
const UNKNOWN_REGION = 'ZZ';

const NANPA_COUNTRY_CODE = 1;
/*
* The prefix that needs to be inserted in front of a Colombian landline number when dialed from
* a mobile number in Colombia.
*/
const COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX = '3';
// The PLUS_SIGN signifies the international prefix.
const PLUS_SIGN = '+';
const PLUS_CHARS = '++';
Expand Down Expand Up @@ -2441,12 +2436,7 @@ public function formatNumberForMobileDialing(PhoneNumber $number, $regionCalling
if ($regionCallingFrom == $regionCode) {
$isFixedLineOrMobile = ($numberType == PhoneNumberType::FIXED_LINE) || ($numberType == PhoneNumberType::MOBILE) || ($numberType == PhoneNumberType::FIXED_LINE_OR_MOBILE);
// Carrier codes may be needed in some countries. We handle this here.
if ($regionCode == 'CO' && $numberType == PhoneNumberType::FIXED_LINE) {
$formattedNumber = $this->formatNationalNumberWithCarrierCode(
$numberNoExt,
static::COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX
);
} elseif ($regionCode == 'BR' && $isFixedLineOrMobile) {
if ($regionCode === 'BR' && $isFixedLineOrMobile) {
// Historically, we set this to an empty string when parsing with raw input if none was
// found in the input string. However, this doesn't result in a number we can dial. For this
// reason, we treat the empty string the same as if it isn't set at all.
Expand Down
2 changes: 2 additions & 0 deletions src/RegionCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* Class containing string constants of region codes for easier testing.
* @internal
*/
class RegionCode
{
Expand All @@ -39,6 +40,7 @@ class RegionCode
const CH = 'CH';
const CL = 'CL';
const CN = 'CN';
const CO = 'CO';
const CS = 'CS';
const CX = 'CX';
const DE = 'DE';
Expand Down
7 changes: 7 additions & 0 deletions tests/core/PhoneNumberUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PhoneNumberUtilTest extends TestCase
{
const TEST_META_DATA_FILE_PREFIX = '../../tests/core/data/PhoneNumberMetadataForTesting';
private static $bsNumber;
private static $coFixedLine;
private static $internationalTollFree;
private static $sgNumber;
private static $usShortByOneNumber;
Expand Down Expand Up @@ -71,6 +72,8 @@ private static function initializePhoneUtilForTesting()
{
self::$bsNumber = new PhoneNumber();
self::$bsNumber->setCountryCode(1)->setNationalNumber(2423651234);
self::$coFixedLine = new PhoneNumber();
self::$coFixedLine->setCountryCode(57)->setNationalNumber(6012345678);
self::$bsMobile = new PhoneNumber();
self::$bsMobile->setCountryCode(1)->setNationalNumber(2423591234);
self::$internationalTollFree = new PhoneNumber();
Expand Down Expand Up @@ -1034,6 +1037,10 @@ public function testFormatNumberForMobileDialing()
{
// Numbers are normally dialed in national format in-country, and international format from
// outside the country.
$this->assertEquals(
'6012345678',
$this->phoneUtil->formatNumberForMobileDialing(self::$coFixedLine, RegionCode::CO, false)
);
$this->assertEquals(
'030123456',
$this->phoneUtil->formatNumberForMobileDialing(self::$deNumber, RegionCode::DE, false)
Expand Down

0 comments on commit caed0f1

Please sign in to comment.