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!
Trending in Proposals
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 10 of 24 Posts
michalmuskala
AstonJ
Another great example of how the core team actively promotes community involvement
…and can I just say, congrats on joining the Elixir Core Team Michał

Qqwy
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
Calendarand what should be part of timezones? Would timezones play a role when using a calendar other thanCalendar.ISO?And also from me, congrats on joining the Core team, Michał!
kip
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 asCalendar.ISO.josevalim
I believe those questions are exactly what the proposals should answer.
Although it feels like leap seconds is a bit orthogonal to the timezone concerns? In any case it is unclear if it will be up to the calendar to perform the timezone lookup or if it will be handled separately.
Qqwy
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:
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.
josevalim
Yes, to be more precise about the first two points. Any DateTime has enough information to convert back to UTC. However, we are unable to receive a NaiveDateTime and a timezone and convert it to DateTime, exactly because we lack the timezone information that would tell us if a wall clock occurs once, twice or not at all in that timezone. This is the smallest proposed change I can see being done to the stdlib.
benwilson512
A post was split to a new topic: Elixir and RFCs
Qqwy
Last post before bed-time, I hope I am still awake to make sense:
I currently think we need the following functionality:
First and foremost, to ensure that the timezones can be used with any calendar, they will work on the
Calendar.iso_daystype:iso_daysin the ‘zero’ time (the timezoneless, non-offset time; for ISO8601 this would be UTC), return theday_fractionthis timezone is offset from the ‘zero’ time.iso_daysin the current timezone, return a list of zero, one or two (is more possible?)day_fractionelements that are offsets from this current timezoneiso_daysto create possibleiso_daysin the ‘zero’ time.Besides these two pieces of core functionality, we might want to standardize some metadata-fields that timezone-implementations should specify, like:
Exactly from where these calls should be initiated, what modules are in control of the flow, and how it should be wrapped is, I presume, part of the concrete implementation details that are to be considered later.
But from user-land, I think these might be exposed like following
):
(Here goes the initial attempt at naming things; be gentle
(This call at least fails if specified string does not identify any known timezone. Are there other potential sources of failure?)
(This call at least fails if specified string does not identify any known timezone. If the timezone is found but the NaiveDateTime does not indicate any valid time, the result list will be empty. Are there other potential edge cases?)
That’s all for now, more tomorrow. I look forward to your critiques!
josevalim
4 posts were split to a new topic: Should Calendar types and timezones be part of Elixir standard library?