Cldr Calendars v0.8.0 Cldr.Calendar.Interval View Source

Implements functions to return intervals and compare date intervals.

In particular it provides functions which return an interval (as a Date.Range.t) for years, quarters, months, weeks and days.

Link to this section Summary

Functions

Compare two date ranges.

Returns a Date.Range.t that represents the day.

Returns a Date.Range.t that represents the year.

Returns a Date.Range.t that represents the quarter.

Returns a Date.Range.t that represents the year.

Returns a Date.Range.t that represents the year.

Link to this section Functions

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

Returns a Date.Range.t that represents the day.

The range is enumerable.

Arguments

Returns

  • A Date.Range.t() representing the the enumerable days in the week

Examples

iex> Cldr.Calendar.Interval.day 2019, 52, Cldr.Calendar.US
#DateRange<%Date{calendar: Cldr.Calendar.US, day: 21, month: 2, year: 2019}, %Date{calendar: Cldr.Calendar.US, day: 21, month: 2, year: 2019}>

iex> Cldr.Calendar.Interval.day 2019, 92, Cldr.Calendar.NRF
#DateRange<%Date{calendar: Cldr.Calendar.NRF, day: 1, month: 14, year: 2019}, %Date{calendar: Cldr.Calendar.NRF, day: 1, month: 14, year: 2019}>

Cldr.Calendar.Interval.day 2019, 8, Cldr.Calendar.ISOWeek
#DateRange<%Date{calendar: Cldr.Calendar.ISOWeek, day: 1, month: 2, year: 2019}, %Date{calendar: Cldr.Calendar.ISOWeek, day: 1, month: 2, year: 2019}>
Link to this function

day(year, day, calendar \\ Cldr.Calendar.Gregorian) View Source

Returns a Date.Range.t that represents the year.

The range is enumerable.

Arguments

Returns

  • A Date.Range.t() representing the the enumerable days in the month

Examples

iex> Cldr.Calendar.Interval.month 2019, 3, Cldr.Calendar.UK
#DateRange<%Date{calendar: Cldr.Calendar.UK, day: 1, month: 3, year: 2019}, %Date{calendar: Cldr.Calendar.UK, day: 30, month: 3, year: 2019}>

iex> Cldr.Calendar.Interval.month 2019, 3, Cldr.Calendar.US
#DateRange<%Date{calendar: Cldr.Calendar.US, day: 1, month: 3, year: 2019}, %Date{calendar: Cldr.Calendar.US, day: 31, month: 3, year: 2019}>
Link to this function

month(year, month, calendar \\ Cldr.Calendar.Gregorian) View Source

Returns a Date.Range.t that represents the quarter.

The range is enumerable.

Arguments

Returns

  • A Date.Range.t() representing the the enumerable days in the quarter

Examples

iex> Cldr.Calendar.Interval.quarter 2019, 2, Cldr.Calendar.UK
#DateRange<%Date{calendar: Cldr.Calendar.UK, day: 1, month: 4, year: 2019}, %Date{calendar: Cldr.Calendar.UK, day: 30, month: 6, year: 2019}>

iex> Cldr.Calendar.Interval.quarter 2019, 2, Cldr.Calendar.ISOWeek
#DateRange<%Date{calendar: Cldr.Calendar.ISOWeek, day: 1, month: 14, year: 2019}, %Date{calendar: Cldr.Calendar.ISOWeek, day: 7, month: 26, year: 2019}>
Link to this function

quarter(year, quarter, calendar \\ Cldr.Calendar.Gregorian) View Source

Returns a Date.Range.t that represents the year.

The range is enumerable.

Arguments

Returns

  • A Date.Range.t() representing the the enumerable days in the week or

  • {:error, :not_defined} if the calendar does not support the concept of weeks

Examples

iex> Cldr.Calendar.Interval.week 2019, 52, Cldr.Calendar.US
#DateRange<%Date{calendar: Cldr.Calendar.US, day: 22, month: 12, year: 2019}, %Date{calendar: Cldr.Calendar.US, day: 28, month: 12, year: 2019}>

iex> Cldr.Calendar.Interval.week 2019, 52, Cldr.Calendar.NRF
#DateRange<%Date{calendar: Cldr.Calendar.NRF, day: 1, month: 52, year: 2019}, %Date{calendar: Cldr.Calendar.NRF, day: 7, month: 52, year: 2019}>

iex> Cldr.Calendar.Interval.week 2019, 52, Cldr.Calendar.ISOWeek
#DateRange<%Date{calendar: Cldr.Calendar.ISOWeek, day: 1, month: 52, year: 2019}, %Date{calendar: Cldr.Calendar.ISOWeek, day: 7, month: 52, year: 2019}>

iex> Cldr.Calendar.Interval.week 2019, 52, Cldr.Calendar.Julian
{:error, :not_defined}
Link to this function

week(year, week, calendar \\ Cldr.Calendar.Gregorian) View Source

Returns a Date.Range.t that represents the year.

The range is enumerable.

Arguments

Returns

  • A Date.Range.t() representing the the enumerable days in the year

Examples

iex> Cldr.Calendar.Interval.year 2019, Cldr.Calendar.UK
#DateRange<%Date{calendar: Cldr.Calendar.UK, day: 1, month: 1, year: 2019}, %Date{calendar: Cldr.Calendar.UK, day: 31, month: 12, year: 2019}>

iex> Cldr.Calendar.Interval.year 2019, Cldr.Calendar.NRF
#DateRange<%Date{calendar: Cldr.Calendar.NRF, day: 1, month: 1, year: 2019}, %Date{calendar: Cldr.Calendar.NRF, day: 7, month: 52, year: 2019}>
Link to this function

year(year, calendar \\ Cldr.Calendar.Gregorian) View Source