Theme Circle

Time Zones are Giving you Headaches When Developing? There is a Cure For That.

Time Zones are Giving you Headaches When Developing? There is a Cure For That.

“If China is 8 hours ahead of us, why didn’t they warn us about it?” someone asked on Reddit and Twitter, causing an outbreak of laughter and many mean comments. Funny as it is, there simply seems to be a lack of understanding of time zones on the part of the person asking the question.

Truth is, time zone differences are here to stay, and should not be overlooked as easily. With the Earth rotating, and one half of it being in the dark for several hours a day there had to be some adjustments made to the clock. If the whole planet was following the same time zone, then half of the population would have to turn into night owls. That would be a mess for each of them personally and also globally create chaos, both economically and socially.

The jet-set lifestyle has turned into your regular workday. Business people hopping from one country to another for a single meeting is not uncommon, and they do know that time zones are an important aspect they should not forget about. It is not a big deal if you missed a phone call from a friend because you expected it to be two hours later. However, if you are a keynote speaker on an important conference, this two-hour mistake is much more costly.

On the other hand, with many freelancers and developers working for companies from all over the globe from the comfort of their own home, the time zone difference (just like the data breach) can cost them their job. Not adjusting to the company’s time zone before an important meeting could lose them a potential client, without having to fly through the air in the first place.

With this in mind, it is important to know that China could not have warned anyone about anything. But, we can warn you, that your web application should be time zone sensitive, especially if any aspect of it is time-related. With Timezone API, regardless of one’s location, your apps being in the right place at the right time is no longer as difficult to achieve.

What is the Timezone API?

If you have a global application, either a mobile one or web one, it would be pretty horrible if you displayed a midnight’s “Happy New Year!” message to a user who is yet to experience the new year euphoria in about 13 hours. And let’s not forget that if a user sets the notification setting to “Do not Disturb after 5”, it doesn’t necessarily mean your 5 o’clock.

While it may sound trivial it is crucial for many things. If any website or an application is based on scheduled events, for example, or if it handles any meetings that might experience misunderstandings due to the time zones, this API could be a job-saver. Thanks to IP Geolocation, you can simply use an already existing solution, without having to actually invent one.

Unsurprisingly, this is a common trouble for developers when creating the application, as there is quite an amount of variables included. Let’s not forget countries with daylight savings time who could end up turning an hour late to an event. Truth is, there are multiple solutions for this, but most of them are quite nerve-wracking, and developers on forums are unable to agree on what should be the best practice. Yet, the simplest solution is integrating the Timezone API.

Timezone API is the secret sauce that developers should be using while creating time-sensitive applications. It enables displaying and searching for time-sensitive information in an application or on a website by both location and time, regardless of anyone’s position in the world.

What are the features of Timezone API and how can I use it?

The important part that you would need to know if you are looking to search for an event, for example, by a date, time or time zone parameters, is that Timezone API can be called in three ways to accommodate these needs. Each of these can serve different purposes, and while the response would be almost the same, you do not have to stick to a specific piece of information to get the required response.

1.  For a time zone

If you are looking for a specific time zone, by knowing the time zone’s valid name, there should be no sweat. What you would need to do is pass the valid name of the time zone as a tz query parameter. For example:

# Get ‘America/Los_Angeles' time zone information
$ curl ‘https://api.ipgeolocation.io/timezone?apiKey=API_KEY&tz=America/Los_Angeles'

The response you will get in return will look like this and contain the much-needed information:

{
    "timezone": "America/Los_Angeles",
    "timezone_offset": -8,
    "date": "2018-12-06",
    "date_time": "2018-12-06 02:02:09",
    "date_time_txt": "Thursday, December 06, 2018 02:02:09",
    "date_time_wti": "Thu, 06 Dec 2018 02:02:09 -0800",
    "date_time_ymd": "2018-12-06T02:02:09-0800",
    "date_time_unix": 1544090529.989,
    "time_24": "02:02:09",
    "time_12": "02:02:09 AM",
    "week": "49",
    "month": "12",
    "year": "2018",
    "year_abbr": "18",
    "is_dst": false,
    "dst_savings": 1
}

2.  For location

If you are looking to search for a specific time zone by location, you should probably have the location’s coordinates by your side. What you need is longitude and latitude of a location, and they can be passed as a query to find out information about the time zone of the location in question. The query should look like this:

# Get time zone information for -27.4748, 153.017 coordinates
$ curl ‘https://api.ipgeolocation.io/timezone?apiKey=API_KEY&lat=-27.4748&long=153.017'

The result should look like this, probably with a different time zone, though:

{
    "timezone": "Asia/Tokyo",
    "timezone_offset": 9,
    "date": "2018-12-06",
    "date_time": "2018-12-06 19:03:52",
    "date_time_txt": "Thursday, December 06, 2018 19:03:52",
    "date_time_wti": "Thu, 06 Dec 2018 19:03:52 +0900",
    "date_time_ymd": "2018-12-06T19:03:52+0900",
    "date_time_unix": 1544090632.434,
    "time_24": "19:03:52",
    "time_12": "07:03:52 PM",
    "week": "49",
    "month": "12",
    "year": "2018",
    "year_abbr": "18",
    "is_dst": false,
    "dst_savings": 0
}

3.  For any IP address

Probably the most accurate solution for the time zone issue is to check by IP address. This way you can make sure that the time zone is relevant to the IP address. Any IPv4 or IPv6 address can be used in the query to get the time zone. Here is an example to demonstrate it:

# Get time zone information for IP address ‘1.1.1.1'
$ curl ‘https://api.ipgeolocation.io/timezone?apiKey=API_KEY&ip=1.1.1.1'

The results will provide you with both the time zone information and geographical data, which you can use for different purposes if need be. The important thing to add here is that Timezone API does not save this information, in accordance with GDPR. Here is an example of the response:

{
    "geo": {
        "country_code2": "AU",
        "country_code3": "AUS",
        "country_name": "Australia",
        "state_prov": "Queensland",
        "district": "South Brisbane",
        "city": "South Brisbane",
        "zipcode": "4101",
        "latitude": "-27.4748",
        "longitude": "153.017"
    },
    "timezone": "Australia/Brisbane",
    "timezone_offset": 10,
    "date": "2018-12-06",
    "date_time": "2018-12-06 20:06:30",
    "date_time_txt": "Thursday, December 06, 2018 20:06:30",
    "date_time_wti": "Thu, 06 Dec 2018 20:06:30 +1000",
    "date_time_ymd": "2018-12-06T20:06:30+1000",
    "date_time_unix": 1544090790.407,
    "time_24": "20:06:30",
    "time_12": "08:06:30 PM",
    "week": "49",
    "month": "12",
    "year": "2018",
    "year_abbr": "18",
    "is_dst": false,
    "dst_savings": 0
}

Of course, in a pinch, when you don’t have the time or any of these parameters ready to go, you can still call this API. You can use the calling machine’s API to get the regional time zone. Here is an example of how you can do it:

$ curl ‘https://api.ipgeolocation.io/timezone?apiKey=API_KEY'

Perfect! How much?

Each of these three features you can get and use completely for free. The free package includes 1500 request per day, and if you go with a paid package, you will be able to get 100,000 responses daily for your money.

There is no such thing as daily, weekly or monthly limit with paid plans, so if you still need to send more requests than that, you will not hit a wall. You will just be surcharged accordingly, based on the plan of your choice. If you decide that you do not need to exceed the free limit, you can always cancel your plan, no strings attached.

All of these are served over a secure HTTPS connection, even without the paid package, so you can rest assured that your application’s security will not be compromised while using IP Geolocation’s solution.

An additional feature that comes with the paid plan is multiple languages. The Timezone API will originally reply in English, as it is the default language. Yet, if you are using a paid version of this API, you can receive the information back in eight other languages. All you should do to change the language in which the API replies is to pass the language code as a query parameter lang.

Timezone API has improved your web application and made your project manager happy?

You might want to check out other APIs created by ipgeolocation.io, and score even more credit with your boss or clients. Two other APIs available on their website are IP Geolocation API, which can help you determine where an IP came from, so that you can customize the user’s experience or, you could use Astronomy API. It provides you with information about the Sun rising and setting time for a specific location which is perfect for those “track your sleeping habits” applications.

The important thing to mention is that all these three APIs can solve all your time zone, geolocation and astronomy issues, for free.

There is a paid plan, which you can sign up for, and you can always rely on their 7 days free trial in case you are still unsure that one of these APIs will make your struggles with JSON or XML programming disappear.

The truth is, since this is a relatively new database, the IP Geolocation guys are just an email away, even if you need something tailor-made. They have already some interesting projects on their hands so you might want to keep an eye on them for additional solutions that can make your life easier!

Exit mobile version