Reputation: 3297
I'm developing rails project, which contain searching for a users. Each user have:
I am searching for the most fast and simple way to get user's local time or time zone.
My ideas:
get city coordinates via google api, and after - get timezone by voordinates
get time zone using other specific rest API
But this realisation of this ideas is not good cause of long request/responce delays... So it is not suitable for me.
Questions:
Does some Exchange API exists to get user's time zone by email?
Can you advise me better ways (JS, RoR or EWS API way) to get user's time zone?
Thanks!
Upvotes: 1
Views: 460
Reputation: 144
You could try to solve this via our new API
curl -s 'https://api.teleport.org/api/cities/?search=Tallinn,%20Estonia&embed=city:search-results/city:item/city:timezone/tz:offsets-now' | jq '._embedded."city:search-results"[0]._embedded."city:item"._embedded."city:timezone"'
This would run a search on Teleport API for city matching 'Tallinn, Estonia' and would fetch the timezone information for the result.
I used ./jq to parse it, the result would look like:
{
"_embedded": {
"tz:offsets-now": {
"_links": {
"self": {
"href": "https://api.teleport.org/api/timezones/iana:Europe%2FTallinn/offsets/?date=2015-09-07T11%3A41%3A00Z"
}
},
"base_offset_min": 120,
"dst_offset_min": 60,
"end_time": "2015-10-25T01:00:00Z",
"short_name": "EEST",
"total_offset_min": 180,
"transition_time": "2015-03-29T01:00:00Z"
}
},
"_links": {
"self": {
"href": "https://api.teleport.org/api/timezones/iana:Europe%2FTallinn/"
},
"tz:offsets": {
"href": "https://api.teleport.org/api/timezones/iana:Europe%2FTallinn/offsets/{?date}",
"templated": true
},
"tz:offsets-now": {
"href": "https://api.teleport.org/api/timezones/iana:Europe%2FTallinn/offsets/?date=2015-09-07T11%3A41%3A00Z"
}
},
"iana_name": "Europe/Tallinn"
}
Upvotes: 1
Reputation: 3297
My algorithm:
if timezone value is not found in TimezoneDictionary - make a request for timezone to Google API, and save it into TimezoneDictionary:
a) request for coordinates via Google Geolocation API
b) request for timezone via Google TimeZone API
And when we have timezone value ("Europe/Kyiv" e.g.) we can get local time with ActiveSupport:
local_time = Time.now.in_time_zone "Europe/Kyiv"
P.S. I created a gem which_time for this issue (to get timzone/time by city name e.g.), so if you have the desire - use it :). I will be very thankful for pull request.
Upvotes: 0