ElixirConf 2019: Date, Time, and Time Zones in Elixir 1.9 - Lau Taarnskov

by @Lau

Elixir 1.8 and 1.9 bring changes to the date & time features in Elixir. This talk will go through how to get the most out of Elixir, as it stands now, for date and time functionalities.

Date and time are a part of every Elixir project. Whether it be timestamps in logs, databases, or business logic, date and time issues have the potential to cause significant problems if you are not prepared.

The TimeZoneDatabase behavior in Elixir 1.8+ allows using time zone functionality directly in the standard library. We’ll walk through examples of how to use it and take advantage of the potential for fewer dependencies.

We will look at the different built-in types for date and time in Elixir. And when to use which one. Choosing the correct type is about semantics, meaning, representing information and data you have available, and avoiding creating fake data. This makes it easier for other developers, other libraries, and other systems to make the most of your date and time data.

We will also look at the new UTC DateTime sigil introduced in Elixir 1.9.

Learn about persisting the date and time types in databases with Ecto 3.

Civil time used today ultimately is tied to how the earth and sun move in relation to each other. This affects leap seconds, which are part of UTC. Besides that, there are many time zones which are determined politically and can change often and with short notice. In certain cases, this can be ignored. The types NaiveDateTime, Date and Time follow rules that do not change often because they are not concerned with these issues. But DateTime depend on an ever-changing database concerning time zones.

How do we keep the time zone database up to date whether deploying to a web server using Phoenix, using containers or to a Nerves device? There are different ways of doing that with different tradeoffs.

Besides looking at how to configure the Tzdata library to use with the TimeZoneDatabase behavior, also get a behind the scenes look at how this library evolved over the last five years. See how both macros and ETS have been used, and which tradeoffs have been made for performance improvements.

View all threads tagged with #time
View all #elixirconf2019 talks