Calendrical.Reform.England (Calendrical v2.2.0)

Copy Markdown

A composite calendar that tracks the historical calendar in use in England.

England's road to the Gregorian calendar spans three transitions rather than a single cutover, which makes it a good demonstration of a composite that splices calendars differing in both their year-start and their leap rule. Two of the transitions only move where the year number changes; the third drops eleven days.

Transitions

  • (base) — the Julian calendar.

  • 1155-03-25 — the year-start moves to March 25 (Lady Day / Annunciation Style), modelled by Calendrical.Julian.March25.

  • 1751-03-25 — the year-start moves to January 1, modelled by Calendrical.Julian.Jan1. As a result the calendar year 1751 is a short year: it runs from 25 March to 31 December.

  • 1752-09-14 — England adopts the proleptic Gregorian calendar. The eleven days 3 September 1752 through 13 September 1752 are skipped, so 2 September 1752 is followed directly by 14 September 1752.

The Lady Day year 1155 keeps the number of the Julian year it begins in, so its dates from 1155-01-01 (25 March) name the days the Julian dates 1 January to 24 March 1155 would. Those 83 Julian days have no date of their own: as Calendrical.Composite describes, a conversion or shift that reaches one answers 1155-01-01, the first later day that has a date, and Date.diff/2 across them counts them.

Examples

# The day before 25 March 1155 has no date of its own
iex> Date.add(~D[1155-01-01 Calendrical.Reform.England], -1)
~D[1155-01-01 Calendrical.Reform.England]

iex> Date.diff(~D[1155-01-01 Calendrical.Reform.England], ~D[1154-12-31 Calendrical.Reform.England])
84

# The eleven days lost to the 1752 Gregorian adoption
iex> Calendrical.Reform.England.valid_date?(1752, 9, 5)
false

iex> Date.shift(~D[1752-09-02 Calendrical.Reform.England], day: 1)
~D[1752-09-14 Calendrical.Reform.England]

# 1751 is a short year, ending on 31 December. The year 1750
# before it carries Lady Day counted months, so its last day is
# month 13 day 24, the Julian 24 March 1751.
iex> Date.shift(~D[1750-13-24 Calendrical.Reform.England], day: 1)
~D[1751-03-25 Calendrical.Reform.England]

Reference

See Calendrical.Reform for the reform dates of other territories and the sources they are drawn from.

Summary

Functions

Adds whole years, quarters or months to the fields of a naive datetime, keeping its time of day: the add/9 callback CalendarInterval steps an interval of a year or a month with. The date moves as shift/6 moves it, clamping the day into a shorter month.

Returns what this calendar's year is built of, :month or :week, as its info/0 states.

Identify the member calendar in effect on a given date struct.

Identify the base calendar for a given date.

Identify the base calendar for a given iso_days.

Returns the calendar module whose CLDR calendar type is the one given, whichever calendar is asked (Calendrical.calendar_from_cldr_calendar_type/1).

Returns the day a date is written with: the day of its written_date/3.

Returns the CLDR month a month of the year names without a year (Calendrical.Month.cldr_month/2).

Returns the year a date is written with: the year of its written_date/3.

Returns the CLDR calendar type whose data names this calendar's months, days and quarters, as its info/0 states.

Returns the CLDR calendar type whose data names a date's months and days: the member in effect on the date in a composite calendar, and this calendar's own otherwise (Calendrical.Info.cldr_calendar_type/4).

Returns the CLDR month of a month of a year (Calendrical.Month.cldr_month/3).

Returns the cyclic year of a date (Calendrical.Era.cyclic_year/4).

Returns the date of this calendar that written figures name (date_from_written_date/3), as fields.

Returns the date of a day of a year, counted from the year's first day.

Returns {year, month, day} calculated from the number of iso_days.

Returns the date of a day of a week of a week-year (Calendrical.Week.date_from_week_date/4).

Returns the date of this calendar that written figures name: the date of the member calendar in effect on the day they name, in this calendar's own fields.

Returns the number of days since the ISO epoch for the given year-month-day.

Returns the dates of this calendar, earliest first, whose month and day are those given and that fall in a Gregorian year.

Returns the days a month of a year has, as runs of their numbers (Calendrical.Month.day_numbers/3).

Calculates the day and era for the given date.

Returns the day of the year of a date (Calendrical.Period.day_of_year/4).

Returns the number of days in a month without a year (Calendrical.Month.days_in_month/2).

Returns the number of days in the given year and month.

Returns the fewest and the most days a month has in any year (Calendrical.Month.days_in_month_bounds/2).

Returns the number of days in a week.

Returns the number of days in a year (Calendrical.Period.days_in_year/2).

Returns the whole number of date_parts from one {year, month, day} to another, as shift/6 adds them, counted through each calendar a span crosses.

Returns the CLDR calendar type that names this calendar's eras, as its info/0 states.

Returns the extended year of a date (Calendrical.Era.extended_year/4).

Returns the static facts about this calendar, as Calendrical.Info.t/0: its members, each with the first day it is in effect on, its base member's year 0 and the weeks of the member in effect last.

Returns the ISO 8601 week-year and week of the day a date names (Calendrical.Week.iso_week_of_year/4).

Returns the position of a year's leap month, or nil where the year has none.

Returns whether the given year is a leap year: the calendar in effect on its first day counts it one, and the day the leap year adds is a date of this calendar.

Returns the traditional month at a position in a year (Calendrical.Month.traditional_month/3), or an error for a place the year does not have.

Returns the days of a month of a year (Calendrical.Period.month/3).

Returns the position of a traditional month in a year (Calendrical.Month.month_from_traditional/3).

Returns the months a year has, as runs of their numbers (Calendrical.Month.month_numbers/2).

Returns the CLDR month of a month of a year: the index of its name in this calendar's CLDR data, with {month, :leap} where the name has a leap form (Calendrical.Month.cldr_month/3).

Returns the number of months in a leap year: the most months a year of this calendar has.

Returns the number of months in an ordinary year: the fewest months a year of this calendar has.

Returns the number of months in a year without a year: the count where every year has as many, {:ambiguous, range} where a leap year has more, and {:error, %Calendrical.NotDefinedError{}} for a composite calendar (Calendrical.Info.months_in_year/1).

Returns the number of the last month of the given year that has days, which is the number of months in a year a transition does not cut short.

Returns the fewest and the most months a year has (Calendrical.Month.months_in_year_bounds/1).

Converts ISO days and a day fraction to a naive datetime of this calendar, as Calendar.naive_datetime_from_iso_days/1 asks.

Converts a naive datetime of this calendar to ISO days and a day fraction, as Calendar.naive_datetime_to_iso_days/7 asks.

Returns the days of a named month in a year (Calendrical.Month.named_month/3).

Returns the number a date's month is written with in figures: the month of its written_date/3.

Returns the position in a year of a traditional month (Calendrical.Month.month_from_traditional/3), as {:ok, month}.

Parses a date written in this calendar's own notation.

Parses a naive datetime written in this calendar's own notation.

Parses a UTC datetime written in this calendar's own notation.

Returns the calendar a date written for this calendar is parsed in, as its info/0 states.

Returns the calendars a date written for this calendar may be written in: the members of a composite calendar, and this calendar alone otherwise (Calendrical.Info.parsing_calendars/1).

Returns the number of periods in a year: its months.

Returns the days of a quadrimester of a year (Calendrical.Period.quadrimester/3).

Returns the days of a quarter of a year (Calendrical.Period.quarter/3).

Returns the quarter of the year a date falls in (Calendrical.Period.quarter_of_year/4).

Returns the days of a semester of a year (Calendrical.Period.semester/3).

Adds an increment number of date_parts to the given year-month-day, always returning a date of this calendar.

Shifts a date by a duration: its years and months together, as shift/6 adds months, and then its weeks and days.

Shifts a naive datetime by a duration: its date as shift_date/4 shifts it, and its time as Calendar.ISO does.

Returns the day of a solar term of a Gregorian year, reckoned at the place this calendar's info/0 names, or at the Chinese calendar's meridian, the traditional reference, where it names none.

Returns the traditional number of the month a year's leap month follows, or nil (Calendrical.Month.traditional_leap_month/2).

Returns a month of a year as this calendar names it (Calendrical.Month.traditional_month/3).

Returns a year's months in order, named traditionally (Calendrical.Month.traditional_months/2).

Determines if the date given is valid according to this calendar.

Returns the seven days of a week of a year (Calendrical.Week.week/3).

Returns the week-year, the week and the day of the week of a date (Calendrical.Week.week_date_from_date/4).

Returns the month and the week of the month a date is in (Calendrical.Week.week_of_month/4).

Returns the week-year and the week of the year a date is in (Calendrical.Week.week_of_year/4).

Returns the number of weeks in a week-year (Calendrical.Week.weeks_in_week_year/2).

Returns the number of weeks in a year (Calendrical.Week.weeks_in_year/2).

Returns the weeks of a month of a year in order (Calendrical.Week.weeks_of_month/3).

Returns the figures a date is written with: the member calendar's.

Returns the days of a year (Calendrical.Period.year/2).

Returns the year of era and era of a year (Calendrical.Era.year_of_era/2).

Calculates the year and era from the given year, month, and day. The result is in the context of the calendar in effect on that date.

Returns the number of years after which this calendar's years repeat, as its info/0 states, or {:error, %Calendrical.NotDefinedError{}}.

Types

day()

@type day() :: 1..31

month()

@type month() :: 1..12

year()

@type year() :: -9999..9999

Functions

add(year, month, day, hour, minute, second, microsecond, atom, step)

Adds whole years, quarters or months to the fields of a naive datetime, keeping its time of day: the add/9 callback CalendarInterval steps an interval of a year or a month with. The date moves as shift/6 moves it, clamping the day into a shorter month.

Arguments

  • year, month and day are the date's fields in this calendar.

  • hour, minute, second and microsecond are the time of day, returned unchanged.

  • precision is :year, :quarter or :month.

  • step is the number of years, quarters or months to add, which may be negative.

Returns

  • {year, month, day, hour, minute, second, microsecond}.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {year, month, day, 12, 30, 0, {0, 0}} =
...>   Calendrical.Reform.England.add(date.year, date.month, date.day, 12, 30, 0, {0, 0}, :month, 1)
iex> {year, month, day} == Calendrical.Reform.England.shift(date.year, date.month, date.day, :months, 1, [])
true

calendar_base()

Returns what this calendar's year is built of, :month or :week, as its info/0 states.

Returns

  • :week for a calendar whose year is built of weeks.

  • :month otherwise.

Examples

iex> Calendrical.Reform.England.calendar_base() in [:month, :week]
true

calendar_for_date(date)

Identify the member calendar in effect on a given date struct.

A date of this calendar is looked up by its year, month and day. A date of any other calendar is first converted to this calendar.

Arguments

  • date is any date map with :year, :month, :day and :calendar fields, such as a Date.t/0.

Returns

  • The member calendar module in effect on the date.

  • Raises if a date of another calendar cannot be converted to this calendar.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.calendar_for_date(date) ==
...>   Calendrical.Reform.England.calendar_for_date(date.year, date.month, date.day)
true
iex> Calendrical.Reform.England.calendar_for_date(~D[2024-06-01]) ==
...>   Calendrical.Reform.England.calendar_for_date(date)
true

calendar_for_date(year, month, day)

Identify the base calendar for a given date.

This function derives the calendar we delegate to for a given date based upon the configuration.

Arguments

  • year is a year of this calendar.

  • month is a month of the year.

  • day is a day of the month.

Returns

  • The member calendar module in effect on the date.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> calendar = Calendrical.Reform.England.calendar_for_date(date.year, date.month, date.day)
iex> calendar in Enum.map(Calendrical.Reform.England.info().members, &elem(&1, 1))
true

calendar_for_iso_days(iso_days)

Identify the base calendar for a given iso_days.

Arguments

  • iso_days is an integer number of days since the ISO epoch.

Returns

  • The member calendar module in effect on that day.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> iso_days = Date.to_gregorian_days(~D[2024-06-01])
iex> Calendrical.Reform.England.calendar_for_iso_days(iso_days) ==
...>   Calendrical.Reform.England.calendar_for_date(date.year, date.month, date.day)
true

calendar_from_cldr_calendar_type(calendar_type)

Returns the calendar module whose CLDR calendar type is the one given, whichever calendar is asked (Calendrical.calendar_from_cldr_calendar_type/1).

Arguments

  • calendar_type is a CLDR calendar type as an atom or a string.

Returns

  • {:ok, calendar_module}, or

  • {:error, exception} for a calendar type no calendar module has.

Examples

iex> Calendrical.Reform.England.calendar_from_cldr_calendar_type(:gregorian)
{:ok, Calendrical.Gregorian}

iex> {:error, %Localize.UnknownCalendarError{}} =
...>   Calendrical.Reform.England.calendar_from_cldr_calendar_type(:not_a_calendar)

cardinal_day(year, month, day)

Returns the day a date is written with: the day of its written_date/3.

Arguments

  • year, month and day are a date of this calendar.

Returns

  • The day of the date's written_date/3, or

  • {:error, %Calendrical.InvalidDateError{}} for a date the calendar does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {_year, _month, written_day} = Calendrical.Reform.England.written_date(date.year, date.month, date.day)
iex> Calendrical.Reform.England.cardinal_day(date.year, date.month, date.day) == written_day
true

cardinal_month(month)

Returns the CLDR month a month of the year names without a year (Calendrical.Month.cldr_month/2).

Arguments

  • month is a month of this calendar.

Returns

  • The CLDR month the month is named in the year that holds 1 January 2000, the month itself in the Hebrew calendar, whose names depend on the year, and the month itself where the reference year has no such month.

Examples

iex> {:ok, date} = Date.convert(~D[2000-01-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.cardinal_month(1) == Calendrical.Reform.England.cldr_month(date.year, 1)
true

cardinal_year(year, month, day)

Returns the year a date is written with: the year of its written_date/3.

Arguments

  • year, month and day are a date of this calendar.

Returns

  • The year of the date's written_date/3, or

  • {:error, %Calendrical.InvalidDateError{}} for a date the calendar does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {written_year, _month, _day} = Calendrical.Reform.England.written_date(date.year, date.month, date.day)
iex> Calendrical.Reform.England.cardinal_year(date.year, date.month, date.day) == written_year
true

cldr_calendar_type()

Returns the CLDR calendar type whose data names this calendar's months, days and quarters, as its info/0 states.

Returns

  • A CLDR calendar type such as :gregorian or :hebrew.

Examples

iex> Calendrical.Reform.England.cldr_calendar_type() == Calendrical.Reform.England.info().cldr_calendar_type
true

cldr_calendar_type(year, month, day)

Returns the CLDR calendar type whose data names a date's months and days: the member in effect on the date in a composite calendar, and this calendar's own otherwise (Calendrical.Info.cldr_calendar_type/4).

Arguments

  • year, month and day are a date of this calendar.

Returns

  • A CLDR calendar type.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> in_effect = Calendrical.Info.in_effect(Calendrical.Reform.England, date.year, date.month, date.day)
iex> Calendrical.Reform.England.cldr_calendar_type(date.year, date.month, date.day) == in_effect.cldr_calendar_type()
true

cldr_month(year, month)

Returns the CLDR month of a month of a year (Calendrical.Month.cldr_month/3).

Arguments

  • year and month are a month of this calendar.

Returns

  • A CLDR month number, or {month, :leap} where the month's name has a leap form, or

  • {:error, exception} for a month the year does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> cldr_month = Calendrical.Reform.England.cldr_month(date.year, date.month)
iex> Calendrical.Reform.England.written_month_from_cldr_month(date.year, cldr_month) ==
...>   Calendrical.Reform.England.numeric_month(date.year, date.month, date.day)
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidMonthError{}} = Calendrical.Reform.England.cldr_month(date.year, 99)

cyclic_year(year, month, day)

Returns the cyclic year of a date (Calendrical.Era.cyclic_year/4).

Arguments

  • year, month and day are a date of this calendar.

Returns

  • The date's place in the sexagenary cycle, 1 to 60, in an East Asian calendar, and its year in a calendar whose years run in no such cycle, or

  • {:error, %Calendrical.InvalidDateError{}} for a year the calendar does not have, or

  • {:error, exception}, a Calendrical.MissingFieldsError, for no year.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> cyclic_year = Calendrical.Reform.England.cyclic_year(date.year, date.month, date.day)
iex> cyclic_year in 1..60 or cyclic_year == date.year
true

iex> {:error, %Calendrical.MissingFieldsError{}} = Calendrical.Reform.England.cyclic_year(nil, 1, 1)

date_from_cardinal_date(year, month, day)

Returns the date of this calendar that written figures name (date_from_written_date/3), as fields.

Arguments

  • year, month and day are the figures a date is written with, as written_date/3 returns them.

Returns

  • {year, month, day}, the date of this calendar, or

  • {:error, %Calendrical.InvalidDateError{}} where the figures name no date.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {year, month, day} = Calendrical.Reform.England.written_date(date.year, date.month, date.day)
iex> Calendrical.Reform.England.date_from_cardinal_date(year, month, day) == {date.year, date.month, date.day}
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidDateError{}} = Calendrical.Reform.England.date_from_cardinal_date(date.year, 0, 1)

date_from_day_of_year(year, day_of_year)

Returns the date of a day of a year, counted from the year's first day.

Arguments

  • year is a year of this calendar.

  • day_of_year is the day of the year, counted from 1.

Returns

  • A Date.t/0 of this calendar, or

  • {:error, %Calendrical.InvalidDateError{}} for a day the year does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> day_of_year = Calendrical.Reform.England.day_of_year(date.year, date.month, date.day)
iex> Calendrical.Reform.England.date_from_day_of_year(date.year, day_of_year) == date
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidDateError{}} = Calendrical.Reform.England.date_from_day_of_year(date.year, 1000)

date_from_iso_days(iso_days)

Returns {year, month, day} calculated from the number of iso_days.

A day whose date is another day's, where two stretches of days carry the same dates, has no date of its own and is written as the first later day that has one, as a shift into the days a reform took out reaches the day after them: England's 1 January to 24 March 1156, whose dates are 1155's, are written as 25 March 1156.

Arguments

  • iso_days is an integer number of days since the ISO epoch.

Returns

  • {year, month, day}, the date of this calendar for the day, as the member calendar in effect on it writes it.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.date_from_iso_days(Date.to_gregorian_days(~D[2024-06-01]))
{date.year, date.month, date.day}

date_from_week_date(week_year, week, day)

Returns the date of a day of a week of a week-year (Calendrical.Week.date_from_week_date/4).

Arguments

  • week_year is a week-year of this calendar.

  • week is a week of the week-year.

  • day is the day of the week, numbered from 1 for the day the calendar's weeks begin on.

Returns

  • A Date.t/0 of this calendar, or

  • {:error, %Calendrical.InvalidDateError{}} where the week has no such day.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {week_year, week, day} = Calendrical.Reform.England.week_date_from_date(date.year, date.month, date.day)
iex> Calendrical.Reform.England.date_from_week_date(week_year, week, day) == date
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidDateError{}} = Calendrical.Reform.England.date_from_week_date(date.year, 1, 8)

date_from_written_date(year, month, day)

Returns the date of this calendar that written figures name: the date of the member calendar in effect on the day they name, in this calendar's own fields.

Arguments

  • year is the written year.

  • month is the written month, an integer or {number, :leap} for the leap month of a lunisolar member.

  • day is the written day.

Returns

  • {:ok, {year, month, day}} with the date of this calendar the figures name.

  • {:error, :invalid_date} if no member calendar in effect on the day reads the figures as a date, an atom as Calendrical.date_from_written_date/3 answers.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {year, month, day} = Calendrical.Reform.England.written_date(date.year, date.month, date.day)
iex> Calendrical.Reform.England.date_from_written_date(year, month, day)
{:ok, {date.year, date.month, date.day}}
iex> Calendrical.Reform.England.date_from_written_date(date.year, 13, 40)
{:error, :invalid_date}

date_to_iso_days(year, month, day)

Returns the number of days since the ISO epoch for the given year-month-day.

Arguments

  • year is a year of this calendar.

  • month is a month of the year.

  • day is a day of the month.

Returns

  • The number of days since the ISO epoch, as an integer, computed by the member calendar in effect on the date.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.date_to_iso_days(date.year, date.month, date.day) ==
...>   Date.to_gregorian_days(~D[2024-06-01])
true

dates_in_gregorian_year(gregorian_year, month, day)

Returns the dates of this calendar, earliest first, whose month and day are those given and that fall in a Gregorian year.

Arguments

  • gregorian_year is the Gregorian year to search within.

  • month and day are a month and a day of this calendar.

Returns

  • A list of zero, one or two Date.t/0 of this calendar, earliest first, since this calendar's years and the Gregorian years drift.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> date in Calendrical.Reform.England.dates_in_gregorian_year(2024, date.month, date.day)
true

day_numbers(year, month)

Returns the days a month of a year has, as runs of their numbers (Calendrical.Month.day_numbers/3).

Arguments

  • year and month are a month of this calendar.

Returns

  • A list of ranges: one from 1 in every month of every calendar but a composite, whose month a change of calendar falls in has the days that are left, and [] for a month the year does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.day_numbers(date.year, date.month) ==
...>   [1..Calendrical.Reform.England.days_in_month(date.year, date.month)//1]
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.day_numbers(date.year, 99)
[]

day_of_era(year, month, day)

Calculates the day and era for the given date.

The era is the one the calendar in effect on the date gives, and its days are counted in one count through every change of calendar the era runs through: that of the calendar in effect where the era begins, or where it ends for an era whose days are counted back from its last. So the day after 2 September 1752 in England, 14 September, is the next day of the era.

Arguments

  • year is a year of this calendar.

  • month is a month of the year.

  • day is a day of the month.

Returns

  • {day_of_era, era} where day_of_era is the day within the era and era is the era's index, the same era year_of_era/3 gives.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {day_of_era, era} = Calendrical.Reform.England.day_of_era(date.year, date.month, date.day)
iex> {_year_of_era, year_era} = Calendrical.Reform.England.year_of_era(date.year, date.month, date.day)
iex> day_of_era >= 1 and era == year_era
true

day_of_week(year, month, day, starting_on)

Returns the day of the week of a date (Calendrical.Week.day_of_week/5).

Arguments

  • year, month and day are a date of this calendar.

  • starting_on is :default for the day this calendar's weeks begin on, or the name of a weekday, :monday to :sunday.

Returns

  • {day_of_week, 1, 7}, the day numbered from the day the week begins on, or

  • {:error, %Calendrical.InvalidDateError{}} for a date the calendar does not have, or

  • {:error, exception}, a Calendrical.MissingFieldsError, for a missing field.

Examples

# 1 June 2024 is a Saturday
iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.day_of_week(date.year, date.month, date.day, :monday)
{6, 1, 7}

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidDateError{}} = Calendrical.Reform.England.day_of_week(date.year, date.month, 0, :monday)

day_of_year(year, month, day)

Returns the day of the year of a date (Calendrical.Period.day_of_year/4).

Arguments

  • year, month and day are a date of this calendar.

Returns

  • The day of the year, counted from 1 for its first day, or

  • {:error, %Calendrical.InvalidDateError{}} for a date the calendar does not have, or

  • {:error, exception}, a Calendrical.MissingFieldsError, for a missing field.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> first_day = Calendrical.Reform.England.year(date.year).first
iex> Calendrical.Reform.England.day_of_year(date.year, date.month, date.day) == Date.diff(date, first_day) + 1
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidDateError{}} = Calendrical.Reform.England.day_of_year(date.year, date.month, 0)

days_in_month(month)

Returns the number of days in a month without a year (Calendrical.Month.days_in_month/2).

Arguments

  • month is a month of this calendar.

Returns

  • The number of days where the month has as many in every year, or

  • {:ambiguous, lengths} where its length depends on the year, the lengths a range or, where they are not consecutive, a list, or

  • {:error, %Calendrical.NotDefinedError{}} for a month the calendar has in no year, or

  • {:error, exception}, a Calendrical.MissingFieldsError, where the month is nil.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {fewest, most} = Calendrical.Reform.England.days_in_month_bounds(date.month)
iex> case Calendrical.Reform.England.days_in_month(date.month) do
...>   days when is_integer(days) -> fewest == days and most == days
...>   {:ambiguous, lengths} -> Enum.min(lengths) == fewest and Enum.max(lengths) == most
...> end
true

iex> {:error, %Calendrical.NotDefinedError{}} = Calendrical.Reform.England.days_in_month(99)

days_in_month(year, month)

@spec days_in_month(Calendar.year(), Calendar.month()) ::
  Calendar.day() | {:error, Exception.t()}

Returns the number of days in the given year and month.

A month a transition cuts short, or splits between two calendars, counts only the days that carry its label: England's September 1752 has 19 days (1 and 2, then 14 to 30). A month no day carries has none: England's January and February 1751, since its 1751 began on 25 March.

Arguments

  • year is a year of this calendar.

  • month is a month of the year.

Returns

  • The number of days that carry the label of year and month, or

  • {:error, %Calendrical.InvalidMonthError{}} for a month no day carries, or

  • {:error, %Calendrical.MissingFieldsError{}} where year or month is nil.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.days_in_month(date.year, date.month) >= date.day
true
iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidMonthError{month: 0}} = Calendrical.Reform.England.days_in_month(date.year, 0)

days_in_month_bounds(month)

Returns the fewest and the most days a month has in any year (Calendrical.Month.days_in_month_bounds/2).

Arguments

  • month is a month of this calendar.

Returns

  • {fewest, most}, or

  • {:error, exception} for a month the calendar has in no year.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {fewest, most} = Calendrical.Reform.England.days_in_month_bounds(date.month)
iex> Calendrical.Reform.England.days_in_month(date.year, date.month) in fewest..most
true

iex> {:error, %Calendrical.InvalidMonthError{}} = Calendrical.Reform.England.days_in_month_bounds(99)

days_in_week()

Returns the number of days in a week.

Returns

  • 7.

Examples

iex> Calendrical.Reform.England.days_in_week()
7

days_in_year(year)

Returns the number of days in a year (Calendrical.Period.days_in_year/2).

Arguments

  • year is a year of this calendar.

Returns

  • The number of days, or

  • {:error, %Calendrical.InvalidDateError{}} for a year the calendar does not have, or

  • {:error, exception}, a Calendrical.MissingFieldsError, for no year.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.days_in_year(date.year) == Enum.count(Calendrical.Reform.England.year(date.year))
true

iex> {:error, %Calendrical.MissingFieldsError{}} = Calendrical.Reform.England.days_in_year(nil)

diff(from, to, date_part)

Returns the whole number of date_parts from one {year, month, day} to another, as shift/6 adds them, counted through each calendar a span crosses.

Arguments

  • from is the {year, month, day} the count starts from.

  • to is the {year, month, day} the count ends at.

  • date_part is one of :years, :quarters, :months, :weeks or :days.

Returns

  • The largest whole number of date_parts shift/6 can add to the earlier date without passing the later one, as an integer. It is negative when to is before from.

  • {:error, %Calendrical.InvalidDateError{}} for a from or to the calendar does not have, {:error, %Calendrical.MissingFieldsError{}} for one missing a field, or {:error, %Calendrical.InvalidPartError{}} for a date_part other than the five.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> from = {date.year, date.month, date.day}
iex> to = Calendrical.Reform.England.shift(date.year, date.month, date.day, :months, 3)
iex> Calendrical.Reform.England.diff(from, to, :months)
3
iex> Calendrical.Reform.England.diff(to, from, :months)
-3

era_calendar_type()

Returns the CLDR calendar type that names this calendar's eras, as its info/0 states.

Returns

  • A CLDR calendar type such as :gregorian or :japanese.

Examples

iex> Calendrical.Reform.England.era_calendar_type() == Calendrical.Reform.England.info().era_calendar_type
true

extended_year(year, month, day)

Returns the extended year of a date (Calendrical.Era.extended_year/4).

Arguments

  • year, month and day are a date of this calendar.

Returns

  • The year numbered without a gap at 0, so that in a calendar with no year 0 the year before 1 is 0, or

  • {:error, %Calendrical.InvalidDateError{}} for a date the calendar does not have, or

  • {:error, exception}, a Calendrical.MissingFieldsError, for no year.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.extended_year(date.year, date.month, date.day) == date.year
true

iex> {:error, %Calendrical.MissingFieldsError{}} = Calendrical.Reform.England.extended_year(nil, 1, 1)

info()

Returns the static facts about this calendar, as Calendrical.Info.t/0: its members, each with the first day it is in effect on, its base member's year 0 and the weeks of the member in effect last.

Returns

  • A Calendrical.Info.t/0 describing this calendar, whose :members are {first_iso_day, calendar} tuples in the order the member calendars take effect, the base calendar's first day being nil.

Examples

iex> Calendrical.Reform.England.info().calendar
Calendrical.Reform.England
iex> match?([{nil, _base_calendar} | _], Calendrical.Reform.England.info().members)
true

iso_week_of_year(year, month, day)

Returns the ISO 8601 week-year and week of the day a date names (Calendrical.Week.iso_week_of_year/4).

Arguments

  • year, month and day are a date of this calendar.

Returns

  • {week_year, week} of ISO 8601, or

  • {:error, exception} for a date the calendar does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.iso_week_of_year(date.year, date.month, date.day)
{2024, 22}

leap_month(year)

Returns the position of a year's leap month, or nil where the year has none.

Arguments

  • year is a year of this calendar.

Returns

  • The leap month's position in the year, or

  • nil where the year has no leap month, as for anything but an integer year.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> leap_month = Calendrical.Reform.England.leap_month(date.year)
iex> is_nil(leap_month) or leap_month in 1..Calendrical.Reform.England.months_in_year(date.year)
true

leap_year?(year)

Returns whether the given year is a leap year: the calendar in effect on its first day counts it one, and the day the leap year adds is a date of this calendar.

Arguments

  • year is a year of this calendar.

Returns

  • true if the member calendar in effect on the first day of year counts it a leap year and the day its leap year adds, the last day of a lengthened month or the first day of a leap month, is a date of this calendar; otherwise false, as for a year with no days of its own (months_in_year/1 is 0) and for a year a change of calendar took the leap day from, as Sweden's 1700 has no 29 February.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> calendar = Calendrical.Reform.England.calendar_for_date(date.year, 1, 1)
iex> Calendrical.Reform.England.leap_year?(date.year) == calendar.leap_year?(date.year)
true

lunar_month_of_year(year, month)

Returns the traditional month at a position in a year (Calendrical.Month.traditional_month/3), or an error for a place the year does not have.

Arguments

  • year and month are a month of this calendar.

Returns

  • The month's traditional number, or {month, :leap} for a leap month, or

  • {:error, %Calendrical.InvalidMonthError{}} for a month the year does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.lunar_month_of_year(date.year, date.month) ==
...>   Calendrical.Reform.England.traditional_month(date.year, date.month)
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidMonthError{}} = Calendrical.Reform.England.lunar_month_of_year(date.year, 99)

month(year, month)

Returns the days of a month of a year (Calendrical.Period.month/3).

Arguments

  • year and month are a month of this calendar.

Returns

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> date in Calendrical.Reform.England.month(date.year, date.month)
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidDateError{}} = Calendrical.Reform.England.month(date.year, 99)

month_from_traditional(year, traditional_month)

Returns the position of a traditional month in a year (Calendrical.Month.month_from_traditional/3).

Arguments

  • year is a year of this calendar.

  • traditional_month is a month's traditional number, or {month, :leap} for a leap month.

Returns

  • The month's position in the year, or

  • {:error, exception} where the year has no such month.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> traditional_month = Calendrical.Reform.England.traditional_month(date.year, date.month)
iex> Calendrical.Reform.England.month_from_traditional(date.year, traditional_month) == date.month
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidMonthError{}} = Calendrical.Reform.England.month_from_traditional(date.year, 99)

month_numbers(year)

Returns the months a year has, as runs of their numbers (Calendrical.Month.month_numbers/2).

Arguments

  • year is a year of this calendar.

Returns

  • A list of ranges: one from 1 in every year of every calendar but a composite, whose year a change of calendar falls in has the months that are left, and [] for a year the calendar does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.month_numbers(date.year) == [1..Calendrical.Reform.England.months_in_year(date.year)//1]
true

month_of_year(year, month, day)

Returns the CLDR month of a month of a year: the index of its name in this calendar's CLDR data, with {month, :leap} where the name has a leap form (Calendrical.Month.cldr_month/3).

Arguments

  • year, month and day are a date of this calendar. The year and the day may be nil: a month's name needs only the month.

Returns

  • A CLDR month number, or {month, :leap}, or

  • {:error, %Calendrical.InvalidDateError{}} for a day the month does not have, or

  • {:error, exception} for a month the year does not have, or a Calendrical.MissingFieldsError where the month is nil.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.month_of_year(date.year, date.month, date.day) == Calendrical.Reform.England.cldr_month(date.year, date.month)
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidDateError{}} = Calendrical.Reform.England.month_of_year(date.year, date.month, 0)

months_in_leap_year()

Returns the number of months in a leap year: the most months a year of this calendar has.

Returns

  • A positive integer.

Examples

iex> Calendrical.Reform.England.months_in_leap_year() >= Calendrical.Reform.England.months_in_ordinary_year()
true

months_in_ordinary_year()

Returns the number of months in an ordinary year: the fewest months a year of this calendar has.

Returns

  • A positive integer.

Examples

iex> Calendrical.Reform.England.months_in_ordinary_year() <= Calendrical.Reform.England.months_in_leap_year()
true

months_in_year()

Returns the number of months in a year without a year: the count where every year has as many, {:ambiguous, range} where a leap year has more, and {:error, %Calendrical.NotDefinedError{}} for a composite calendar (Calendrical.Info.months_in_year/1).

Returns

  • The number of months where every year has as many, or

  • {:ambiguous, fewest..most} where a leap year has more, or

  • {:error, %Calendrical.NotDefinedError{}} for a composite calendar, whose bounds months_in_year_bounds/0 gives.

Examples

iex> case Calendrical.Reform.England.months_in_year() do
...>   months when is_integer(months) -> months == Calendrical.Reform.England.months_in_leap_year()
...>   {:ambiguous, fewest..most//1} -> {fewest, most} == Calendrical.Reform.England.info().months_in_year
...>   {:error, %Calendrical.NotDefinedError{}} -> is_list(Calendrical.Reform.England.info().members)
...> end
true

months_in_year(year)

Returns the number of the last month of the given year that has days, which is the number of months in a year a transition does not cut short.

England's 1751, which began on 25 March, has months 3 to 12 and answers 12; Russia's 1492, which ended on 31 August, answers 8. A year no day carries answers 0.

Arguments

  • year is a year of this calendar.

Returns

  • The number of the last month of the year that has days, as a non-negative integer. It is 0 for a year no day carries, or

  • {:error, %Calendrical.MissingFieldsError{}} where year is nil, or

  • {:error, %Calendrical.InvalidDateError{}} where year is no integer.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.months_in_year(date.year) >= date.month
true

months_in_year_bounds()

Returns the fewest and the most months a year has (Calendrical.Month.months_in_year_bounds/1).

Returns

  • {fewest, most}, which in a composite calendar counts the months left in a year a change of calendar falls in.

Examples

iex> {fewest, most} = Calendrical.Reform.England.months_in_year_bounds()
iex> fewest <= Calendrical.Reform.England.months_in_ordinary_year() and
...>   most >= Calendrical.Reform.England.months_in_leap_year()
true

naive_datetime_from_iso_days(arg)

Converts ISO days and a day fraction to a naive datetime of this calendar, as Calendar.naive_datetime_from_iso_days/1 asks.

Arguments

  • iso_days is {days, {parts_in_day, parts_per_day}}, a day and a fraction of it.

Returns

  • {year, month, day, hour, minute, second, microsecond} of this calendar.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {year, month, day, 12, 0, 0, {0, 6}} =
...>   Calendrical.Reform.England.naive_datetime_from_iso_days({739403, {43200000000, 86400000000}})
iex> {year, month, day} == {date.year, date.month, date.day}
true

naive_datetime_to_iso_days(year, month, day, hour, minute, second, microsecond)

Converts a naive datetime of this calendar to ISO days and a day fraction, as Calendar.naive_datetime_to_iso_days/7 asks.

Arguments

  • year, month and day are a date of this calendar.

  • hour, minute, second and microsecond are a time of day, the microsecond as {microseconds, precision}.

Returns

  • {iso_days, {parts_in_day, parts_per_day}}.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.naive_datetime_to_iso_days(date.year, date.month, date.day, 12, 0, 0, {0, 6})
{739403, {43200000000, 86400000000}}

named_month(year, named_month)

Returns the days of a named month in a year (Calendrical.Month.named_month/3).

Arguments

  • year is a year of this calendar.

  • named_month is the CLDR month that names the month.

Returns

  • A list of Date.Range.t/0, one for each counted month that carries the name, earliest first, and [] where none does.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> cldr_month = Calendrical.Reform.England.cldr_month(date.year, date.month)
iex> Calendrical.Reform.England.named_month(date.year, cldr_month) |> Enum.any?(&(date in &1))
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.named_month(date.year, 99)
[]

numeric_month(year, month, day)

Returns the number a date's month is written with in figures: the month of its written_date/3.

Arguments

  • year, month and day are a date of this calendar.

Returns

  • The month of the date's written_date/3: a month number, or {month, :leap} for a leap month of a lunisolar calendar, or

  • {:error, %Calendrical.InvalidDateError{}} for a date the calendar does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {_year, written_month, _day} = Calendrical.Reform.England.written_date(date.year, date.month, date.day)
iex> Calendrical.Reform.England.numeric_month(date.year, date.month, date.day) == written_month
true

ordinal_month_from_traditional(year, traditional_month)

Returns the position in a year of a traditional month (Calendrical.Month.month_from_traditional/3), as {:ok, month}.

Arguments

  • year is a year of this calendar.

  • traditional_month is a month's traditional number, or {month, :leap} for a leap month.

Returns

  • {:ok, month}, the month's position in the year, or

  • {:error, %Calendrical.InvalidMonthError{}} for a month or a leap month the year does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> traditional_month = Calendrical.Reform.England.traditional_month(date.year, date.month)
iex> Calendrical.Reform.England.ordinal_month_from_traditional(date.year, traditional_month) == {:ok, date.month}
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidMonthError{}} = Calendrical.Reform.England.ordinal_month_from_traditional(date.year, 99)

parse_date(string)

Parses a date written in this calendar's own notation.

Arguments

  • string is a date written YYYY-MM-DD, with a leading - for a year before 1, or, in a calendar of weeks, YYYY-Www-D.

Returns

  • {:ok, {year, month, day}}, or

  • {:error, :invalid_format} where the text is not in that form or its fields are not digits, or

  • {:error, :invalid_date} where the text names no date of this calendar.

The reason is an atom, not an exception, because Calendar.parse_date/1 requires one: Date.from_iso8601/2 reads it.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.parse_date(Date.to_string(date)) == {:ok, {date.year, date.month, date.day}}
true

iex> Calendrical.Reform.England.parse_date("not a date")
{:error, :invalid_format}

parse_naive_datetime(string)

Parses a naive datetime written in this calendar's own notation.

Arguments

  • string is a date as parse_date/1 reads it, then T or a space and a time of day.

Returns

  • {:ok, {year, month, day, hour, minute, second, microsecond}}, or

  • {:error, reason}, such as :invalid_format or :invalid_date, where the text is no such datetime.

The reason is an atom, not an exception, because Calendar.parse_naive_datetime/1 requires one: NaiveDateTime.from_iso8601/2 reads it.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.parse_naive_datetime(Date.to_string(date) <> "T12:00:00") ==
...>   {:ok, {date.year, date.month, date.day, 12, 0, 0, {0, 0}}}
true

iex> Calendrical.Reform.England.parse_naive_datetime("2024-06-01")
{:error, :invalid_format}

parse_utc_datetime(string)

Parses a UTC datetime written in this calendar's own notation.

Arguments

  • string is a date as parse_date/1 reads it, then T or a space, a time of day and an offset from UTC, Z or ±HH:MM.

Returns

  • {:ok, {year, month, day, hour, minute, second, microsecond}, offset}, the datetime in UTC and the offset in seconds it was written with, or

  • {:error, reason}, such as :invalid_format, :invalid_date or :missing_offset, where the text is no such datetime.

The reason is an atom, not an exception, because Calendar.parse_utc_datetime/1 requires one: DateTime.from_iso8601/2 reads it.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.parse_utc_datetime(Date.to_string(date) <> "T12:00:00Z") ==
...>   {:ok, {date.year, date.month, date.day, 12, 0, 0, {0, 0}}, 0}
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.parse_utc_datetime(Date.to_string(date) <> "T12:00:00")
{:error, :missing_offset}

parsing_calendar()

Returns the calendar a date written for this calendar is parsed in, as its info/0 states.

Returns

  • A calendar module.

Examples

iex> Calendrical.Reform.England.parsing_calendar() == Calendrical.Reform.England.info().parsing_calendar
true

parsing_calendars()

Returns the calendars a date written for this calendar may be written in: the members of a composite calendar, and this calendar alone otherwise (Calendrical.Info.parsing_calendars/1).

Returns

  • A non-empty list of calendar modules, the members of a composite calendar in the order they take effect.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> in_effect = Calendrical.Info.in_effect(Calendrical.Reform.England, date.year, date.month, date.day)
iex> in_effect in Calendrical.Reform.England.parsing_calendars()
true

periods_in_year(year)

Returns the number of periods in a year: its months.

Arguments

  • year is a year of this calendar.

Returns

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.periods_in_year(date.year) == Calendrical.Reform.England.months_in_year(date.year)
true

quadrimester(year, quadrimester)

Returns the days of a quadrimester of a year (Calendrical.Period.quadrimester/3).

Arguments

  • year is a year of this calendar.

  • quadrimester is the quadrimester, 1 to 3.

Returns

  • A Date.Range.t/0, or

  • {:error, %Calendrical.InvalidDateError{}} for a quadrimester or a year the calendar does not have, or

  • {:error, %Calendrical.MissingFieldsError{}} where the year or the quadrimester is nil.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.quadrimester(date.year, 1).first == Calendrical.Reform.England.year(date.year).first
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidDateError{}} = Calendrical.Reform.England.quadrimester(date.year, 4)

quarter(year, quarter)

Returns the days of a quarter of a year (Calendrical.Period.quarter/3).

Arguments

  • year is a year of this calendar.

  • quarter is the quarter, 1 to 4.

Returns

  • A Date.Range.t/0, or

  • {:error, %Calendrical.InvalidDateError{}} for a quarter or a year the calendar does not have, or

  • {:error, %Calendrical.MissingFieldsError{}} where the year or the quarter is nil.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> quarter = Calendrical.Reform.England.quarter_of_year(date.year, date.month, date.day)
iex> date in Calendrical.Reform.England.quarter(date.year, quarter)
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidDateError{}} = Calendrical.Reform.England.quarter(date.year, 5)

quarter_of_year(year, month, day)

Returns the quarter of the year a date falls in (Calendrical.Period.quarter_of_year/4).

Arguments

  • year, month and day are a date of this calendar.

Returns

  • The quarter, 1 to 4, or

  • {:error, %Calendrical.InvalidDateError{}} for a date the calendar does not have, or

  • {:error, exception}, a Calendrical.MissingFieldsError, for a missing year or month.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.quarter_of_year(date.year, date.month, date.day) in 1..4
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidDateError{}} = Calendrical.Reform.England.quarter_of_year(date.year, date.month, 0)

semester(year, semester)

Returns the days of a semester of a year (Calendrical.Period.semester/3).

Arguments

  • year is a year of this calendar.

  • semester is the semester, 1 or 2.

Returns

  • A Date.Range.t/0, or

  • {:error, %Calendrical.InvalidDateError{}} for a semester or a year the calendar does not have, or

  • {:error, %Calendrical.MissingFieldsError{}} where the year or the semester is nil.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.semester(date.year, 1).first == Calendrical.Reform.England.year(date.year).first
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidDateError{}} = Calendrical.Reform.England.semester(date.year, 3)

shift(year, month, day, date_part, increment, options \\ [])

Adds an increment number of date_parts to the given year-month-day, always returning a date of this calendar.

Years, quarters and months are added in the calendar in effect on the date, a year being as many months as that calendar counts. When the result falls under another calendar the months are counted on through each calendar's own months, so one month after 20 August 1752 in England is 20 September 1752. A day the resulting month does not have becomes the month's next day that exists, or its last day: one month after 5 August 1752 is 14 September 1752 and one month after 31 January is the last day of February. Weeks and days count days.

Arguments

  • year is a year of this calendar.

  • month is a month of the year.

  • day is a day of the month.

  • date_part is one of :years, :quarters, :months, :weeks or :days.

  • increment is the positive or negative integer number of date_parts to add.

  • options is a keyword list of options.

Options

  • :clamp is accepted for the Calendrical.shift/6 callback but has no effect: a day the resulting month does not have is always brought into it as described above.

Returns

  • {year, month, day}, the date of this calendar reached, or

  • {:error, %Calendrical.InvalidDateError{}} where year, month and day are no date of this calendar, or

  • {:error, %Calendrical.MissingFieldsError{}} where a field is nil.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {year, month, day} = Calendrical.Reform.England.shift(date.year, date.month, date.day, :days, 10)
iex> Calendrical.Reform.England.date_to_iso_days(year, month, day) -
...>   Calendrical.Reform.England.date_to_iso_days(date.year, date.month, date.day)
10
iex> to = Calendrical.Reform.England.shift(date.year, date.month, date.day, :years, 1)
iex> Calendrical.Reform.England.diff({date.year, date.month, date.day}, to, :years)
1

shift_date(year, month, day, duration)

Shifts a date by a duration: its years and months together, as shift/6 adds months, and then its weeks and days.

Arguments

  • year, month and day are a date of this calendar.

  • duration is a Duration.t/0.

Returns

  • {year, month, day} of this calendar.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {year, month, day} = Calendrical.Reform.England.shift_date(date.year, date.month, date.day, Duration.new!(day: 7))
iex> Date.new!(year, month, day, Calendrical.Reform.England) == Date.add(date, 7)
true

shift_naive_datetime(year, month, day, hour, minute, second, microsecond, duration)

Shifts a naive datetime by a duration: its date as shift_date/4 shifts it, and its time as Calendar.ISO does.

Arguments

  • year, month and day are a date of this calendar.

  • hour, minute, second and microsecond are a time of day, the microsecond as {microseconds, precision}.

  • duration is a Duration.t/0.

Returns

  • {year, month, day, hour, minute, second, microsecond} of this calendar.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> next_day = Date.add(date, 1)
iex> Calendrical.Reform.England.shift_naive_datetime(date.year, date.month, date.day, 23, 0, 0, {0, 0}, Duration.new!(hour: 2)) ==
...>   {next_day.year, next_day.month, next_day.day, 1, 0, 0, {0, 0}}
true

shift_time(hour, minute, second, microsecond, duration)

Shifts a time by a duration, as Calendar.ISO does.

Arguments

  • hour, minute, second and microsecond are a time of day, the microsecond as {microseconds, precision}.

  • duration is a Duration.t/0 of time units.

Returns

  • {hour, minute, second, microsecond}, wrapped around midnight.

Examples

iex> Calendrical.Reform.England.shift_time(23, 0, 0, {0, 0}, Duration.new!(hour: 2))
{1, 0, 0, {0, 0}}

solar_term(index, gregorian_year)

Returns the day of a solar term of a Gregorian year, reckoned at the place this calendar's info/0 names, or at the Chinese calendar's meridian, the traditional reference, where it names none.

Arguments

  • index is the solar term's number, 1 (lichun, 315° of solar longitude) to 24, every 15° on.

  • gregorian_year is a Gregorian year.

Returns

Examples

# Qingming, the fifth solar term
iex> Calendrical.Reform.England.solar_term(5, 2025)
{:ok, ~D[2025-04-04 Calendrical.Gregorian]}

iex> Calendrical.Reform.England.solar_term(25, 2025)
{:error, %Calendrical.InvalidSolarTermError{index: 25}}

traditional_leap_month(year)

Returns the traditional number of the month a year's leap month follows, or nil (Calendrical.Month.traditional_leap_month/2).

Arguments

  • year is a year of this calendar.

Returns

  • The traditional number of the month the leap month follows, or

  • nil where the year has no leap month.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> is_nil(Calendrical.Reform.England.traditional_leap_month(date.year)) ==
...>   is_nil(Calendrical.Reform.England.leap_month(date.year))
true

traditional_month(year, month)

Returns a month of a year as this calendar names it (Calendrical.Month.traditional_month/3).

Arguments

  • year and month are a month of this calendar.

Returns

  • The month's traditional number, or {month, :leap} for a leap month, or

  • {:error, exception} for a month the year does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.traditional_month(date.year, date.month) ==
...>   Enum.at(Calendrical.Reform.England.traditional_months(date.year), date.month - 1)
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidMonthError{}} = Calendrical.Reform.England.traditional_month(date.year, 99)

traditional_months(year)

Returns a year's months in order, named traditionally (Calendrical.Month.traditional_months/2).

Arguments

  • year is a year of this calendar.

Returns

  • A list of traditional months, the nth naming the year's nth month, with {month, :leap} for a leap month, and [] for a year the calendar does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> length(Calendrical.Reform.England.traditional_months(date.year)) ==
...>   Calendrical.Reform.England.months_in_year(date.year)
true

valid_date?(year, month, day)

Determines if the date given is valid according to this calendar.

A date is valid when the member calendar in effect on it accepts it and the day it names is one that calendar governs, so a date a change of calendar took out is not valid.

Arguments

  • year is a year of this calendar.

  • month is a month of the year.

  • day is a day of the month.

Returns

  • true if the year, month and day are a date of this calendar, otherwise false.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.valid_date?(date.year, date.month, date.day)
true
iex> Calendrical.Reform.England.valid_date?(date.year, date.month, 0)
false

week(year, week)

Returns the seven days of a week of a year (Calendrical.Week.week/3).

Arguments

  • year is a year of this calendar.

  • week is a week of the year.

Returns

  • A Date.Range.t/0 of the week's seven days, which may begin in the year before or end in the year after, or

  • {:error, %Calendrical.InvalidDateError{}} for a week the year does not have, or

  • {:error, %Calendrical.MissingFieldsError{}} where the year or the week is nil.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {week_year, week} = Calendrical.Reform.England.week_of_year(date.year, date.month, date.day)
iex> days = Calendrical.Reform.England.week(week_year, week)
iex> {Enum.count(days), date in days}
{7, true}

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidDateError{}} = Calendrical.Reform.England.week(date.year, 0)

week_date_from_date(year, month, day)

Returns the week-year, the week and the day of the week of a date (Calendrical.Week.week_date_from_date/4).

Arguments

  • year, month and day are a date of this calendar.

Returns

  • {week_year, week, day_of_week}, the day numbered from the day the calendar's weeks begin on, or

  • {:error, %Calendrical.InvalidDateError{}} for a date the calendar does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {week_year, week, day} = Calendrical.Reform.England.week_date_from_date(date.year, date.month, date.day)
iex> {week_year, week} == Calendrical.Reform.England.week_of_year(date.year, date.month, date.day) and day in 1..7
true

week_of_month(year, month, day)

Returns the month and the week of the month a date is in (Calendrical.Week.week_of_month/4).

Arguments

  • year, month and day are a date of this calendar.

Returns

  • {month, week}, where the month is the one before or after where the date falls in that month's last or first week, or

  • {:error, exception} for a date the calendar does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {month, week} = Calendrical.Reform.England.week_of_month(date.year, date.month, date.day)
iex> month in (date.month - 1)..(date.month + 1) and week >= 1
true

week_of_year(year, month, day)

Returns the week-year and the week of the year a date is in (Calendrical.Week.week_of_year/4).

Arguments

  • year, month and day are a date of this calendar.

Returns

  • {week_year, week}, where the week-year is the year before or after where the date falls in that year's last or first week, or

  • {:error, exception} for a date the calendar does not have: a Calendrical.MissingFieldsError for a date missing a field, and a Calendrical.InvalidDateError otherwise.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {week_year, week} = Calendrical.Reform.England.week_of_year(date.year, date.month, date.day)
iex> date in Calendrical.Reform.England.week(week_year, week)
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidDateError{}} = Calendrical.Reform.England.week_of_year(date.year, date.month, 0)

weeks_in_week_year(week_year)

Returns the number of weeks in a week-year (Calendrical.Week.weeks_in_week_year/2).

Arguments

  • week_year is a week-year of this calendar.

Returns

  • The number of weeks, or

  • {:error, %Calendrical.InvalidDateError{}} for a year the calendar does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {week_year, week, _day} = Calendrical.Reform.England.week_date_from_date(date.year, date.month, date.day)
iex> week <= Calendrical.Reform.England.weeks_in_week_year(week_year)
true

weeks_in_year(year)

Returns the number of weeks in a year (Calendrical.Week.weeks_in_year/2).

Arguments

  • year is a year of this calendar.

Returns

  • The number of weeks, or

  • {:error, exception} for a year the calendar does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {week_year, week} = Calendrical.Reform.England.week_of_year(date.year, date.month, date.day)
iex> week <= Calendrical.Reform.England.weeks_in_year(week_year)
true

weeks_of_month(year, month)

Returns the weeks of a month of a year in order (Calendrical.Week.weeks_of_month/3).

Arguments

  • year and month are a month of this calendar.

Returns

  • A list of Date.Range.t/0, one for each week week_of_month/3 names for the month, the first of which may begin in the month before and the last run into the month after, or

  • {:error, exception} for a month the year does not have.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.weeks_of_month(date.year, date.month) |> Enum.all?(&(Enum.count(&1) == 7))
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {:error, %Calendrical.InvalidMonthError{}} = Calendrical.Reform.England.weeks_of_month(date.year, 99)

written_date(year, month, day)

Returns the figures a date is written with: the member calendar's.

Arguments

  • year is a year of this calendar.

  • month is a month of the year.

  • day is a day of the month.

Returns

  • {year, month, day} as the member calendar in effect on the date writes it, where month may be {number, :leap} for the leap month of a lunisolar member.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {year, month, day} = Calendrical.Reform.England.written_date(date.year, date.month, date.day)
iex> Calendrical.Reform.England.date_from_written_date(year, month, day)
{:ok, {date.year, date.month, date.day}}

written_month_from_cldr_month(year, cldr_month)

Returns the month a CLDR month is written with in a year (Calendrical.Month.written_month_from_cldr_month/3).

Arguments

  • year is a year of this calendar.

  • cldr_month is a CLDR month number, or {month, :leap}.

Returns

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {_year, written_month, _day} = Calendrical.Reform.England.written_date(date.year, date.month, date.day)
iex> cldr_month = Calendrical.Reform.England.cldr_month(date.year, date.month)
iex> Calendrical.Reform.England.written_month_from_cldr_month(date.year, cldr_month) == written_month
true

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.written_month_from_cldr_month(date.year, 99)
{:error, :invalid_month}

year(year)

Returns the days of a year (Calendrical.Period.year/2).

Arguments

  • year is a year of this calendar.

Returns

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> date in Calendrical.Reform.England.year(date.year)
true

iex> {:error, %Calendrical.MissingFieldsError{}} = Calendrical.Reform.England.year(nil)

year_of_era(year)

Returns the year of era and era of a year (Calendrical.Era.year_of_era/2).

Arguments

  • year is a year of this calendar.

Returns

  • {year_of_era, era}, the era in effect on the year's first day, or

  • {:error, %Calendrical.InvalidDateError{}} for a year the calendar does not have, or

  • {:error, exception}, a Calendrical.MissingFieldsError, for no year.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> Calendrical.Reform.England.year_of_era(date.year) ==
...>   Calendrical.Reform.England.year_of_era(date.year, date.month, date.day)
true

year_of_era(year, month, day)

@spec year_of_era(year(), month(), day()) :: {year(), era :: non_neg_integer()}

Calculates the year and era from the given year, month, and day. The result is in the context of the calendar in effect on that date.

Arguments

  • year is a year of this calendar.

  • month is a month of the year.

  • day is a day of the month.

Returns

  • {year_of_era, era} where year_of_era is the year within the era and era is the era's index, as the member calendar in effect on the date gives them.

Examples

iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> {year_of_era, era} = Calendrical.Reform.England.year_of_era(date.year, date.month, date.day)
iex> is_integer(year_of_era) and is_integer(era)
true

years_in_cycle()

Returns the number of years after which this calendar's years repeat, as its info/0 states, or {:error, %Calendrical.NotDefinedError{}}.

Returns

  • The number of years in the cycle, or

  • {:error, %Calendrical.NotDefinedError{}} where the calendar states none.

Examples

# A year has as many days as the year one cycle later
iex> {:ok, date} = Date.convert(~D[2024-06-01], Calendrical.Reform.England)
iex> case Calendrical.Reform.England.years_in_cycle() do
...>   {:error, %Calendrical.NotDefinedError{}} -> true
...>   years -> Calendrical.Reform.England.days_in_year(date.year) == Calendrical.Reform.England.days_in_year(date.year + years)
...> end
true