# hlc - Hybrid Logical Clock in Erlang. #

Copyright (c) 2014-2015 Benoît Chesneau.

__Version:__ 1.0.0

hlc implements the Hybrid Logical Clock outlined in [Logical Physical Clocks
and Consistent Snapshots in Globally Distributed

> Note: you can use it to have timestamps that are are a combination of both a
> physical and a logical component to support monotonic increments without
> degenerate cases causing timestamps to diverge from wall clock time. It's
> usefull to distribute transactions or such things.

[![Build Status](](
[![Hex pm](](

## Example of usage

Create a logical clock using `hlc:new/0`:

{ok, C} = hlc:new()

> Note: by default, it is using the physical clock (`erlang:timestamp/0` or `erlang:now/0` on old systems) , but you
> can use `hlc:new/1` to pass a function and use your own clock. Make sure to use the correct [time warp
> mode]( for your system.

You can update the current clock from the members using `hlc:update/2`.

### Comparaison

Compare 2 clocks using `hlc:ts_less/2` or `hlc:ts_equal/2`:

Ex, compare if A is inferior to B:

{MClock, MClockFun} = hlc:manual_clock(),
{ok, C} = hlc:new(MClockFun),

A = hlc:timestamp(C),
B = hlc:timestamp(C),

?assert(A =:= B),

hlc:set_manual_clock(MClock, 1),
B1 = hlc:now(C),
true = enki_util:ts_less(A, B1).

To test if they are equal use `hlc:ts_equal/2`.

## Ownership and License

The contributors are listed in AUTHORS. This project uses the MPL v2
license, see LICENSE.

hlc uses the [C4.1 (Collective Code Construction
Contract)]( process for contributions.

## Development

Under C4.1 process, you are more than welcome to help us by:

* join the discussion over anything from design to code style try out
* and [submit issue reports](
* or feature requests pick a task in
* [issues]( and get it done fork
* the repository and have your own fixes send us pull requests and even
* star this project ^_^

To  run the test suite:

make test