camcaine

camcaine

GMaps Time Zone API flow

On the backend (phoenix app) I have a situation where I am creating Events with a start_date. Every event will have one Location known in advance, with geo (lat lng) coordinates. A concert or sports event for example.

On the client side, rather than ask the user for a time zone directly, I decided that it would be cool to extract that info using the location coords and Google Maps Time Zone API (Get Started  |  Time Zone API  |  Google for Developers).

You pass the coordinates of a location (lat, lng) and a unix timestamp, and it returns the tz name, utc offset, dst offset.

Here is my idea for how it would work:

The user submitted start_date is a NaiveDateTime representing the local/wall time of the event. However the Google API expects the timestamp as unix, which is essentially UTC if I’m correct. So my thinking is that could send the unix current time to the Time Zone API to get the locations timezone. Then use a library like Calendar or Timex to apply this timezone with the naive datetime, to generate a correct DateTime.

It seems a little like going round the houses though :confused: . I did think I could query the location after it’s first created and save the timezone alongside it, but not sure if that would be a bad idea when dealing with tz data.

Any feedback on this flow would be greatly appreciated!

Most Liked

Qqwy

Qqwy

TypeCheck Core Team

You have a problem here, namely that asking the user for wallclock time and then finding out the timezone based on that time as a Unix timestamp means that you already need the timezone to convert said wallclock time to Unix.

POSIX/UNIX time is not at all the same as UTC (although they are somewhat related). Unix time measures the time since 00:00:00 1 January 1970 (UTC) in seconds, while UTC uses the proleptic gregorian calendar, with the addition of leap seconds.

It seems to me that what you actually need, is something that converts local time to ‘server time’ (which might be UTC or any timezone offset based on that), so your application accurately knows when an event starts. The Google Maps Time Zone API endpoint isn’t going to help you here, as you actually need the inverse functionality (user picks location + wall clock time, API returns time in UTC or Unix).

Last Post!

camcaine

camcaine

I follow. But isn’t that always going to be a problem for any system scheduling things into the future, before timezone changes are made?

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New

Other popular topics Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49134 226
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement