# Cldr.Calendar.Interval.compare

You're seeing just the function `compare`, go back to Cldr.Calendar.Interval module for more information.

# compare(r1, r2)

View Source

## Specs

```compare(range_1 :: Date.Range.t(), range_2 :: Date.Range.t()) ::
Cldr.Calendar.interval_relation()```

Compare two date ranges.

Uses Allen's Interval Algebra to return one of 13 different relationships:

RelationConverse
:precedes:preceded_by
:meets:met_by
:overlaps:overlapped_by
:finished_by:finishes
:contains:during
:starts:started_by
:equals:equals

## Arguments

• `range_1` is a `Date.Range.t`

• `range_2` is a `Date.Range.t`

## Returns

An atom representing the relationship between the two ranges.

## Examples

``````iex> Cldr.Calendar.Interval.compare Cldr.Calendar.Interval.day(~D[2019-01-01]),
...> Cldr.Calendar.Interval.day(~D[2019-01-02])
:meets

iex> Cldr.Calendar.Interval.compare Cldr.Calendar.Interval.day(~D[2019-01-01]),
...> Cldr.Calendar.Interval.day(~D[2019-01-03])
:precedes

iex> Cldr.Calendar.Interval.compare Cldr.Calendar.Interval.day(~D[2019-01-03]),
...> Cldr.Calendar.Interval.day(~D[2019-01-01])
:preceded_by

iex> Cldr.Calendar.Interval.compare Cldr.Calendar.Interval.day(~D[2019-01-02]),
...> Cldr.Calendar.Interval.day(~D[2019-01-01])
:met_by

iex> Cldr.Calendar.Interval.compare Cldr.Calendar.Interval.day(~D[2019-01-02]),
...> Cldr.Calendar.Interval.day(~D[2019-01-02])
:equals``````