michalmuskala / time_format

Fast date/time formatting for elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TimeFormat

Library for formatting Elixir calendar structs using the classic strftime syntax.

This library is in development.

Usage

Because most of the time the actual format string is entirely static, the library optimises for that case providing two modes of operation:

  • interpretation - using the TimeFormat.strftime function, behaving like a classical strftime interface accepting a format string and data to format.

    iex> TimeFormat.strftime("%m-%d-%Y", ~D[2017-05-21])
    "05-21-2017"
  • compilation - using the TimeFormat.Compiled.defstrftime and TimeFormat.Compiled.defstrftimep macros offering to compile a particular format into a formatting function accepting just data for best performance.

    defmodule MyFormat do
      import TimeFormat.Compiled
      defstrftime :us_date, "%m-%d-%Y"
    end
    
    iex> MyFormat.us_date(~D[2017-05-21])
    "05-21-2017"

TODO

Installation

If available in Hex, the package can be installed by adding time_format to your list of dependencies in mix.exs:

def deps do
  [
    {:time_format, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/time_format.

About

Fast date/time formatting for elixir


Languages

Language:Elixir 100.0%