Skip to content
Functions for working with calendar intervals
Branch: master
Clone or download
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 Update docs Feb 5, 2018
examples Add gaps example Feb 3, 2018
lib Release v0.1.0 Jan 26, 2019
test Crash on descending intervals, closes #3 Jan 26, 2019
.formatter.exs Initial commit Feb 3, 2018
.gitignore Initial commit Feb 3, 2018
.iex.exs alias I in .iex.exs Feb 5, 2018
.travis.yml Run examples/gaps.exs in test env on CI Jan 26, 2019 Release v0.1.0 Jan 26, 2019 Update docs, add license Feb 3, 2018 Release v0.1.0 Jan 26, 2019
mix.lock Release v0.1.0 Jan 26, 2019


Build Status

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


use CalendarInterval

iex> ~I"2018-06".precision


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")

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


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.


Add to mix.exs:

def deps do
    {:calendar_interval, "~> 0.1"}


Apache 2.0

You can’t perform that action at this time.