Ilya
Ilya

Reputation: 1150

Elixir/Phoenix timestamps local

I have several schemas (Ecto.Schema) and use timestamps for inserted_at, updated_at fields. But it defaults to the Ecto.DateTime and saves time in UTC. Is it possible to use local time, instead of UTC? I've checked the Ecto.Schema but can't seem to find a way to default it to the local time, instead of the UTC. Example:

schema "orders" do

field :number_of_customers, :integer
field :completed, :boolean, default: false

timestamps
end

Thanks!

Upvotes: 0

Views: 2141

Answers (1)

tkowal
tkowal

Reputation: 9299

According to the docs you can do almost whatever you want with the timestamps.

Using options you can specify :type or you can even register custom function that will be called to generate those using :autogenerate.

However I would keep the timestamps in UTC, because this is a standard way. It is strange that it doesn't work for you. Calling Ecto.DateTime.utc shoud just get correct time zone information from the operating system and display correct time in UTC. If that is not the case, maybe your OS has incorrect time zone?

Upvotes: 1

Related Questions