# wojtekmach/calendar_interval

Functions for working with calendar intervals
Elixir
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Feb 5, 2018
examples Feb 3, 2018
lib Jan 26, 2019
test Jan 26, 2019
.formatter.exs Feb 3, 2018
.gitignore Feb 3, 2018
.iex.exs Feb 5, 2018
.travis.yml Jan 26, 2019
CHANGELOG.md Jan 26, 2019
mix.exs
mix.lock Jan 26, 2019

# CalendarInterval

Functions for working with calendar intervals.

Key ideas:

• Time is enumerable: "2018" is a collection of "2018-01/2018-12" months, "2018-01-01/2018-12-31" days etc
• Everything is an interval: "2018" is an interval of 1 year, or 12 months, or 365 days etc. A timestamp with microsecond precision is an interval 1 microsecond long
• Allen's Interval Algebra: formalism for relations between time intervals

## Examples

```use CalendarInterval

iex> ~I"2018-06".precision
:month

iex> CalendarInterval.next(~I"2018-12-31")
~I"2019-01-01"

iex> CalendarInterval.nest(~I"2018-06-15", :minute)
~I"2018-06-15 00:00/23:59"

iex> CalendarInterval.relation(~I"2018-01", ~I"2018-02/12")
:meets

iex> Enum.count(~I"2016-01-01/12-31")
366```

## References

This library is heavily inspired by "Exploring Time" talk by Eric Evans [1] where he mentioned the concept of "Countable Time" and introduced me to "Allen's Interval Algebra" [2].

I've also given a talk about some of these ideas at Empex NYC 2018: video, slides.

## Installation

Add to `mix.exs`:

```def deps do
[
{:calendar_interval, "~> 0.1"}
]
end```