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 (https://developers.google.com/maps/documentation/timezone/start).

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).

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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
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
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
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 30048 115
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New

We're in Beta

About us Mission Statement