Library for formatting Elixir calendar structs using the classic strftime
syntax.
This library is in development.
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
andTimeFormat.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"
- - complete all the formats in
TimeFormat.Format.Utils
- - consider what to do with modifiers in formats like "upcase" - do we really need it?
- - add support for "mnemonic" formatters from timex: https://hexdocs.pm/timex/Timex.Format.DateTime.Formatters.Default.html
- - explore replacing timex and calendar formatting with this library
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.