NIF-based date and time parsing and formatting for Erlang.
Erlang C Makefile Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.rebar
c_src
doc
src Bump version to 0.4.3 May 16, 2016
test
.gitignore
.travis.yml Update list of OTP versions for Travis Apr 1, 2016
LICENSE
Makefile
README.md
rebar.config
rebar_dev.config
start-dev.sh

README.md

tempo Build Status

Authors: Dmitry Groshev (lambdadmitry@gmail.com), Sergei Levedev (superbobry@gmail.com).

tempo is a library for parsing and formatting dates in Erlang. It provides a clean and nice interface to libc's strptime and strftime functions, which are unfortunately missing from Erlang's standard library.

Is it any good?

Yes.

How can I use it?

The only two functions you have to remember are tempo:parse/2 and tempo:format/2. Here are some examples:

1> {ok, Bin} = tempo:format(iso8601, {now, now()}).
{ok,<<"2016-01-11T19:25:26Z">>}
2> tempo:parse(iso8601, {datetime, Bin}).
{ok,{{2016,1,11},{19,25,26}}}

As you might have noticed, both of the functions follow a common pattern -- Format first, then a Value, tagged by its actual or expected type. Predefined formats include: iso8601, rfc1123, and rfc2822, but in fact, you can use any format, as long as it follows libc conventions:

(tempo_dev@localhost)1> {ok, Bin} = tempo:format(<<"%A, %Y-%d-%m">>, {now, now()}).
{ok,<<"Thursday, 2012-07-06">>}

Limitations

Unfortunately, dealing with time on various platforms is messy, so limitations are unavoidable. Here's a shortlist of those we know of:

  • Parsing years before 1900 causes a {error, format_mismatch} on OS X.

Modules

tempo