📎 Webclip
You might not need the Calendar or Timex libraries
Elixir’s standard library now includes native date and time types, time zone calculations through Calendar.TimeZoneDatabase, Unix time conversion, ranges, parsing, formatting, and other common date and time operations. The post argues that for most uses, Calendar or Timex are no longer required.
It recommends preferring the standard library when it offers the same functionality because it means fewer dependencies, more long-term maintenance, and more familiarity across Elixir developers. Third-party libraries still make sense for gaps in the standard library, and time zone calculations still require a time zone database such as tzdata or another TimeZoneDatabase implementation.
Reading notes#
- Elixir 1.3 introduced native date and time types.
- Elixir 1.8 added the
Calendar.TimeZoneDatabasebehaviour for time zone calculations. - The standard library now supports comparison, arithmetic, time zones, Unix time conversion, calendar fields, date ranges, and ISO 8601 parsing and formatting.
Calendar.strftime/3is added on the master branch and is scheduled for Elixir 1.11.- The standard library is preferred when it provides the same feature as a third-party library because it reduces dependencies and increases shared familiarity.
- Third-party libraries are still useful when the standard library does not provide the needed functionality.
- For time zone calculations, applications need a timezone database dependency and configuration such as
tzdata. - Library authors can use
from_naive/3andshift_zone/3and let end users choose the time zone database implementation.
