tz_datetime

Handling timezones for datetimes in ecto


Keywords
ecto, elixir, elixir-lang
License
Apache-2.0

Documentation

TzDatetime

Datetime in a certain timezone with Ecto

Ecto natively only supports naive_datetimes and utc_datetimes, which either ignore timezones or enforce only UTC. Both are useful for certain usecases, but not sufficient when needing to store a datetime for different timezones.

This library is supposed to help for the given use case, but not in the way e.g. Calecto does it by implementing a custom Ecto.Type. It rather gives you tools to set the correct values for multiple columns on a changeset and converting the values back to a DateTime at a later time.

Installation

If available in Hex, the package can be installed by adding tz_datetime to your list of dependencies in mix.exs:

def deps do
  [
    {:tz_datetime, "~> 0.1.2"}
  ]
end

You'll also need to configure elixir to use a timezone database, which supports all the timezones you need to use. Elixir itself does only support Etc/UTC. For other timezones look at tz_data or other implementations of Calendar.TimeZoneDatabase.

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/tz_datetime.