michalmuskala

michalmuskala

Call for proposals: time zone support in Elixir

TL;DR: The Elixir Core team is announcing a call for proposals to extend support for time zones in Elixir’s standard library.

The reasoning

Elixir’s relationship with dates times and calendars used to be bumpy. Fortunately, in the 1.3 release we got the built-in calendar types (DateTime, NaiveDateTime, Date and Time) with a thought-through and hopefully future-proof structure and interface. In the following releases, the number of defined APIs grew and the support for various features and algorithms increased.

Today, all the libraries (timex, calendar, ecto and more) use the built-in structs and define various algorithms using them, which means they are fully inter-operable and there’s no longer the issue of incompatible libraries. The transition is not yet complete, though.

Even though, the DateTime struct semantically defines a point-in-time in a concrete time zone, the Elixir standard library does not ship with the time zone database - this means that the functions in the DateTime module can only operate on structs in the Etc/UTC time zone requiring most libraries to include some third-party solution to deal with datetimes in other time zones.

The are many reasons not to ship with a time zone database, the two primary ones are the increase in size of the standard elixir release and the fact that the time zone database is often updated, which would tie the elixir release schedule to the time zone database update schedule.

The solution

Nonetheless, support for time zones is something we, the Elixir Core team, would like to include in the Elixir’s standard library. Unfortunately, we lack the required expertise and primarily the required time to properly design and implement this feature. That’s why we’ve decided to reach to you, the community, and ask for help. We’re asking you to propose possible solutions within the following design constraints and help us push Elixir forward.

Design constraints

Because we still don’t want to ship with time zone database in Elixir itself, we want the time zone library to be pluggable. To achieve this, the solutions needs two components - an interface for such a library defined in elixir itself (most probably a behaviour with one or more @callbacks) and a library implementing the behaviour and providing the time zone database to the standard library.

We don’t want the interface to be based on the current shape of the tzdata library. It has broad interfaces that often return collections of data you need to further process to retrieve the desired information. This means that for many operations a lot of data needs to be copied from the supporting ets tables making the library slower than it should be. The interface of the proposed library should be focused on speed and offer focused functions that give concrete answers to very specific queries.

When it comes to concrete implementations of the time zone database library there are many possibilities:

  • compile the database into a module using macros;
  • store in ets tables and update dynamically;
  • call some C utility;
  • and possibly more.

It’s important that we don’t want to focus on those yet. We want to look at what functions to define in standard library to take advantage of the time zone database and what interface we need from a time zone database provider. The time for concrete implementations will come later.

Proposal

The proposal should include 2 things:

  • new functions in the Elixir standard library leveraging the time zone database
  • a way to provide the time zone database to the Elixir standard library though a package.

The proposals should be RFC-style. This means they should be actionable and present concrete ideas and APIs, not just talk about principles and possibilities. A proposal should include signatures, typespecs and documentation drafts for all the new modules, functions and callbacks.

We intend Elixir 1.8 (estimated January 2019) to ship with those extensions. Thank you!

Most Liked

AstonJ

AstonJ

Another great example of how the core team actively promotes community involvement :003:

…and can I just say, congrats on joining the Elixir Core Team Michał :023: :tada:

21
Post #3
Qqwy

Qqwy

TypeCheck Core Team

Let it be known that @kip and I are collaborating together on a proposal. We’ll keep you posted :slight_smile:.

kip

kip

ex_cldr Core Team

I would expect timezone support in calendars other than Calendar.ISO. I am nearly completion of a lib supporting other calendars (ISO Week, 445/454/544, various business calendars) that are based upon the Gregorian proleptic calendar but are different. The concept of time, for these calendars, is the same as Calendar.ISO.

Qqwy

Qqwy

TypeCheck Core Team

First and foremost, I’d like to ask: What is the Elixir Core team’s current view on handling leap seconds? Would leap second handling be expected to be part of this new system, would it be ‘opt in’ based on what timezone functionality would be created, or would it explicitly not be something we’d want to consider at this time?

And, related: What functionality should be kept in Calendar and what should be part of timezones? Would timezones play a role when using a calendar other than Calendar.ISO?

And also from me, congrats on joining the Core team, Michał! :cake:

Qqwy

Qqwy

TypeCheck Core Team

This is not yet a proposal, but more a list of known behaviour that timezones exhibit, and which will probably have to be modeled in one way or another to be able to make a proposed Elixir time zone support system useful:

  • In essence, timezones are an offset from a given ‘base’ time. Usually we talk about these offsets relative to UTC time itself (but this of course only makes sense w.r.t the ISO8601 calendar)
  • However, how far timezones are offset might change, meaning that local wall clock time might have times that ‘occur twice’, as well as sections of time that ‘do not appear at all’.
  • When timezones change their offset also varies: The most common form of this is known as daylight savings time, (which some locations start or end at midnight, and others at two in the morning, for instance; also, europe and the US perform their DST shift a couple of weeks apart). However, there are other forms, as well as political reforms that alter the offset permanently for a given geographical region.
  • Above rules mean that when someone creates a datastructure representing a future datetime, they might:
    1. keep it as-is, which will mean it is influenced by (political) changes in timezone rules between ‘now’ and the specified datetime.
    2. transform it to an absolute (i.e. UTC) datetime, which means it will not be influenced by these.
      Whichever one of these is more reasonable depends on the context at hand, so this choice needs to be open to the user (the application programmer).

please tell if you see an oversight, mistake or ommission in here and I’ll update the list.

Where Next?

Popular in Proposals Top

josevalim
NOTE: this is a focused thread, so we appreciate if everybody stayed on topic. Feel free to comment anything in regards to calendar forma...
New
josevalim
Hi everyone, This is a proposal for introducing local accumulators to Elixir. This is another attempt of solving the comprehension probl...
1043 9939 246
New
josevalim
Hi everyone, as you may be aware, we are researching a type system for Elixir. As preparation for my upcoming ElixirConf US talk, I woul...
New
josevalim
I am resubmitting the proposal from earlier today with more context and more focus on the important parts. Some concerns and praises stay...
452 17667 124
New
josevalim
UPDATE: This proposal has been retracted. Read the new proposal here: Local accumulators for cleaner comprehensions Hi everyone, This i...
New
josevalim
One of the major differences between running your application as a release and as a Mix project is the differences in configuration. Mix ...
382 17497 108
New
michalmuskala
TL;DR: The Elixir Core team is announcing a call for proposals to extend support for time zones in Elixir’s standard library. The reason...
New
josevalim
Hi everyone, Erlang/OTP 21 comes with two new guards contributed by @michalmuskala: map_get/2 and is_map_key/2. Now we need to discuss h...
New
josevalim
Hi everyone, We are considering deprecating 'charlists' in Elixir in favor of ~c"charlist". In many languages, 'foobar' is equivalent to...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

We're in Beta

About us Mission Statement