sstephenson / global_phone

Parse, validate, and format phone numbers in Ruby using Google's libphonenumber database
MIT License
549 stars 104 forks source link

Local phone number formatting issue #22

Open futuretap opened 10 years ago

futuretap commented 10 years ago

The national_format returns wrong results in many cases:

GlobalPhone.parse('+4372762580').national_format
=> "0727  62580"

(correct: 07276 2580)

GlobalPhone.parse('+49907896890').national_format
=> "090  7896890"

(correct: 09078 96890)

I think that the problem is not caused by wrong rules in the DB since libPhoneNumber-iOS yields correct results.

wallymathieu commented 9 years ago

Look at pull request #9

futuretap commented 9 years ago

I didn't mean the double white space which is easy to fix. I meant the wrong position of the space.

locochris commented 9 years ago

@futuretap - confirmed using a freshly created global_phone.json (even with the whitespace fix of #9).

I've never tried to understand how the json is being generated, but perhaps there's some information lost when parsing the original xml. I notice a bit of a difference in size (even taking in to account comments and xml bloat).

diff -u <({curl -silent http://libphonenumber.googlecode.com/svn/trunk/resources/PhoneNumberMetadata.xml, global_phone_dbgen} | wc -l)
-   24710
+    6659
wallymathieu commented 9 years ago

You could look at the c# port. I've modified the code to generate a bit more readable json : https://github.com/wallymathieu/GlobalPhone/commit/6eb4eb579ec1d7d740c03da3b3a3dc25a4cc9a19