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 Responses

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

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
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
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
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Other popular topics Top

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
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
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
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
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
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement