I want to write an RoR mobile app which gives me the current time at the country for a given phone number, with its area code. Is there a good api for this?
Not a good idea.
What will you do for countries that have several different time zones and many area codes? There isn't necessarily a one-to-one mapping of time zone to area code.
For example, in the USA, the 928 area code covers much of Arizona, including two different time zones because in the north-eastern portion of the state, the Navajo nation honors daylight savings time while the rest of Arizona does not. So for part of the year there is a one hour difference between two different parts of the 928 area code.
A cleaner example - the 605 area code covers the entire state of South Dakota. The western half of the state uses Mountain Time, and the eastern half of the state uses Central Time.
I'm sure outside of the USA there are plenty of more examples.
Also, people travel with their mobile phones. I know 3 people of the top of my head that kept their phone number with a different area code after moving to a new one.
Also, Mobile Number Portability and Local Number Portability allow for people to move into other areas and keep their phone numbers - including area code. Thus area code only will tell you where the number first originated, not where it currently is.
If you are OK with adding Javascript to your project, then you may want to try ChronoMouse.js, which will help get the current time, GMT offset, time zone name, location, capital city, daylight savings laws, or daylight savings status for any US/Canada area code, or country code.
For country codes, the info is based off of the capital city.
For example:
console.log( getLocalInfo('+49').time.display );
// 15:07
For more examples and documentation, see www.chronomouse.com.
Note: I am the author of the project.
This can help you map country codes to country names https://github.com/hexorx/countries
Countries is a collection of all sorts of useful information for every country in the ISO 3166 standard. It contains info for the following standards ISO3166-1(countries), ISO3166-2(states/subdivisions), ISO4217(currency) and E.164(phone numbers). The gem also adds a country_select helper. I will add any country based data I can get access to. I hope this to be a repository for all country based information.