Skip to content

Commit

Permalink
NANP 1-600 area code and its future expansions are non-geographic
Browse files Browse the repository at this point in the history
  • Loading branch information
DrHyde committed Jan 11, 2023
1 parent f2b0109 commit ec426f0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ X.XXXX XXXX-XX-XX

- Bug fix: NANP toll-free numbers corrected. 833 area code now supported,
and regex fixed to only match when the B and C digits are the same, so
800 is toll-free, 888 is toll-free, but 808 is not.
800 is toll-free, 888 is toll-free, but 808 is not. See
https://github.com/DrHyde/perl-modules-Number-Phone/issues/110

- Bug fix: NANP 1-600 area code is non-geographic. See
https://github.com/DrHyde/perl-modules-Number-Phone/issues/113

- Workaround: OFCOM have the wrong number length for the +44 800 716 range,
we now have an egregious hack to work around that. See
Expand Down
11 changes: 11 additions & 0 deletions lib/Number/Phone/NANP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ not yet be allocated, or it may be reserved.
NANP-globals like 1-800 aren't geographic, the rest are.
As a special case, 1-600 is non-geographic. So too will be
1-622/633/644/655/677/688 when they come in to service.
=item is_mobile
NANP-globals like 1-800 aren't mobile. For most others we just don't know because
Expand Down Expand Up @@ -245,8 +248,16 @@ foreach my $method (qw(areacode subscriber)) {
}
}

sub _is_canadian_600 {
my $self = shift;
${$self} =~ /^(\+1)?6([0234578])\2/;
}

sub is_geographic {
my $self = shift;
# 600 is non-geographic. 6(22|33|44|55|77|88) are reserved
# for non-geographic use but not yet in use
return 0 if($self->_is_canadian_600());
# NANP-globals like 1-800 aren't geographic, the rest are
return ref($self) eq __PACKAGE__ ? 0 : 1;
}
Expand Down
20 changes: 20 additions & 0 deletions t/inc/common-nanp_and_libphonenumber_tests.pl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@

note("Common tests for Number::Phone::NANP and Number::Phone::Lib");

my $ca_600 = $CLASS->new('+1 600 555 1000');
isa_ok $ca_600, is_libphonenumber() ? 'Number::Phone::StubCountry::CA'
: 'Number::Phone::NANP::CA';
is $ca_600->country(), 'CA', "$CLASS->new('+1 600 555 1000')->country()";
is_deeply(
[sort $ca_600->type()],
[sort('is_valid', is_libphonenumber() ? 'is_ipphone' : ())],
"$CLASS->new('+1 600 555 1000')->type()"
);

my $ca_604 = $CLASS->new('+1 604 555 1000');
isa_ok $ca_604, is_libphonenumber() ? 'Number::Phone::StubCountry::CA'
: 'Number::Phone::NANP::CA';
is $ca_604->country(), 'CA', "$CLASS->new('+1 604 555 1000')->country()";
is_deeply(
[sort $ca_604->type()],
[sort qw(is_geographic is_valid)],
"$CLASS->new('+1 604 555 1000')->type()"
);

my $the_man = '+1 (202) 456-6213';
my $us = $CLASS->new($the_man);
isa_ok $us, is_libphonenumber() ? 'Number::Phone::StubCountry::US'
Expand Down

0 comments on commit ec426f0

Please sign in to comment.