Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/selectel/tempo

NIF-based date and time parsing and formatting for Erlang
https://github.com/selectel/tempo

community datetime erlang

Last synced: about 1 month ago
JSON representation

NIF-based date and time parsing and formatting for Erlang

Awesome Lists containing this project

README

        

# tempo [![Build Status](https://github.com/selectel/tempo/workflows/build/badge.svg)](https://github.com/selectel/tempo) #

__Authors:__ Dmitry Groshev ([`[email protected]`](mailto:[email protected])), Sergei Levedev ([`[email protected]`](mailto:[email protected])).

`tempo` is a library for parsing and formatting dates in
Erlang. It provides a clean and nice interface to libc's
[strptime](http://linux.die.net/man/3/strptime) and
[strftime](http://linux.die.net/man/3/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`](https://github.com/selectel/tempo/blob/master/doc/tempo.md#parse-2)
and [`tempo:format/2`](https://github.com/selectel/tempo/blob/master/doc/tempo.md#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