Hello everyone, I am learning Elixir, Absinthe and Ecto and I am making an auctioning site to try and learn multiple aspects of these technologies. But I am super stuck on working with DateTimes. I let my users set the ending time on the auction via HTML
<input type="datetime-local" value="2017-06-01T08:30">
Now I receive this Data object from the input. And can get ISO or UTC string. The issue I have is how to work with this? I have the following schemas
My ecto schema
schema "items" do
field :title, :string
field :description, :string
field :ends_at, :utc_datetime
timestamps()
end
And my Absinthe schema
object :item do
field :id, :id
field :title, :string
field :description, :string
field :ends_at, :date_time
end
scalar :date_time do
parse(fn input ->
case DateTime.from_iso8601(input.value) do
{:ok, datetime, _} -> {:ok, datetime}
_ -> :error
end
end)
serialize(fn date ->
DateTime.to_iso8601(date)
end)
end
Now I need to show every user the correct time that the auction is ending based on their timezone, but I have no idea how to go about this. There are so many different terms being thrown around, timestampz timestamps, date time, naive date time.
I could just use Unix time but I feel like that be giving up on actually learning dates and how to use them, Iād also lose the querying capabilities in Postgres probably.
So I just want to send a date when the auction ends from my client and be able to store it properly in my db so that I can correctly show the date to my users when itās actually ending. Any explanations would be greatly appreciated, I tried playing around with ISO, UTC and other formats from the client but I donāt fully understand how to go about it as there are some kind of timezone databases and what not