Timex is a date and time library for Elixir with Olson timezone support through tzdata, parsing, formatting, and rich calendar arithmetic.
Overview
Timex is an Elixir library for working with dates, times, datetimes, timestamps, and durations when the standard Calendar modules are not enough. It integrates with the :tzdata package for full Olson timezone database support and can interoperate with Ecto types through the separate timex_ecto package.
Core capabilities include creating and converting datetimes across zones, shifting and comparing instants, formatting and parsing datetime strings, building intervals between points in time, and measuring elapsed time. It delegates to Elixir’s standard library where possible and accepts Date, NaiveDateTime, DateTime, and Erlang datetime tuples within documented ISO calendar year bounds.
Timezone handling follows the IANA Olson database, with POSIX-TZ compatibility for custom zones. Tzdata can automatically fetch IANA updates over HTTPS using the operating system’s trusted CA certificates. Setters validate results and surface ambiguous or gap transitions when wall times do not exist.
Extension points include custom Timex.Protocol implementations for proprietary date types, comparable protocols, and pluggable formatters and parsers. Public compare, diff, and conversion helpers retain sensible defaults while lower-level protocol callers supply granularity or timezone explicitly.
Key features
- Olson timezone support via tzdata
- Date and datetime parsing and formatting
- Shift, compare, and diff operations
- Time intervals and durations
- POSIX and IANA timezone rules
- Custom formatter and parser hooks
- Ecto integration via timex_ecto
- Automatic tzdata updates
Use cases
- Timezone-aware Elixir applications
- Parsing and formatting datetime strings
- Calendar arithmetic and intervals
- Ecto-backed timestamp fields
- Measuring function execution time