Gregorian (Calendars v0.2.4) View Source

The Gregorian calendar module.

Link to this section Summary

Functions

Adds the number of days to a fixed day or Gregorian date.

Adds the number of months to a fixed day or Gregorian date.

Adds the number of quarters to a fixed day or Gregorian date.

Adds the number of weeks to a fixed day or Gregorian date.

Adds the number of years to a fixed year or Gregorian date.

Returns the fixed date of Advent Sunday of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

Returns the month april of the Gregorian calendar.

Returns a fixed day or Gregorian date as a Gregorian date.

Returns a fixed day or Gregorian date as a fixed day.

Returns a fixed day or Gregorian date either as a fixed day or a Gregorian date.

Returns the month august of the Gregorian calendar.

Returns a list of the Calixir functions of the Gregorian calendar.

Returns the fixed date of Christmas of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

Compares two Gregorian dates and returns...

Returns a Gregorian date from its fields year, month, day.

Returns the difference (= number of days) between two Gregorian dates.

Returns the day field of a Gregorian date.

Returns the ordinal day number of a fixed day or Gregorian date in the corresponding month.

Returns the ordinal day number of a fixed day or Gregorian date in the corresponding quarter.

Returns the ordinal day number of a fixed day or Gregorian date in the corresponding week.

Returns the ordinal day number of the fixed day or Gregorian date in the equivalent Gregorian year.

Returns the fixed date of Daylight Saving End of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

Returns the fixed date of Daylight Saving Start of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

Returns the number of days in the month of a fixed day or Gregorian date.

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

Returns the number of days in the quarter given by a fixed day or Gregorian date.

Returns the number of days in a week of the Gregorian calendar.

Returns the number of days in the Gregorian year.

Returns the number of days remaing in the month after a fixed day or Gregorian date.

Returns the number of days remaining in the quarter given by a fixed day or Gregorian date.

Returns the number of days remaing after a fixed day or a Gregorian date in the equivalent Gregorian year.

Returns the month december of the Gregorian calendar.

Returns the fixed date of Easter of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

Returns the fixed date of U.S. Election Day of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

Returns the last day of the month given by a fixed day or Gregorian date.

Returns the last day of the month given by the Gregorian year and month.

Returns the last day of the quarter given by a fixed day or a Gregorian date.

Returns the last day of the quarter given by the Gregorian year and quarter.

Returns the end of the week of the fixed day or Gregorian date.

Returns the last day of the Gregorian year given by a fixed day or a Gregorian date.

Returns the fixed date of Epiphany of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

Returns the epoch of the Gregorian calendar.

Returns true if Gregorian date1 is equal Gregorian date2, otherwise false.

Returns the month february of the Gregorian calendar.

Returns the name of the field atom in a Gregorian date at field_index.

Returns a list of the field atoms (names) of a Gregorian date.

Returns the number of fields in a Gregorian date

Returns the index (= position) of the field_atom in a Gregorian date.

Returns the weekday friday of the Gregorian calendar.

Converts the other_date of the other_calendar into the equivalent date of the Gregorian calendar.

Converts a fixed day to a Gregorian date.

Converts a Julian Day into the equivalent Gregorian date.

Converts a RataDie date into the equivalent Gregorian date.

Converts a Unix date into the equivalent Gregorian date.

Returns true if Gregorian date1 is greater (= later) than or equal Gregorian date2, otherwise false.

Returns true if Gregorian date1 is greater (= later) than Gregorian date2, otherwise false.

Returns a list of the holidays of the Gregorian calendar.

Returns the quarter i of the Gregorian calendar.

Returns the quarter ii of the Gregorian calendar.

Returns the quarter iii of the Gregorian calendar.

Returns the fixed date of U.S. Independence Day of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

Returns the quarter iv of the Gregorian calendar.

Returns the month january of the Gregorian calendar.

Returns the month july of the Gregorian calendar.

Returns the month june of the Gregorian calendar.

Returns the internal keyword of the Gregorian calendar.

Returns the fixed date of U.S. Labor Day of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

Returns the last month of the Gregorian year given by a fixed day or a Gregorian date.

Returns true if Gregorian date1 is smaller (= earlier) than or equal Gregorian date2, otherwise false.

Returns true if the Gregorian year is a leap year, otherwise false.

Returns true if Gregorian date1 is smaller (= earlier) than Gregorian date2, otherwise false.

Returns the month march of the Gregorian calendar.

Returns the month may of the Gregorian calendar.

Returns the average length of a Gregorian month.

Returns the average length of a Gregorian quarter.

Returns the average length of a Gregorian year.

Returns the fixed date of U.S. Memorial Day of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

Returns the module of the Gregorian calendar.

Returns the weekday monday of the Gregorian calendar.

Returns the month field of a Gregorian date.

Returns a list of the months of the Gregorian calendar.

Returns the number of months in the Gregorian year.

Returns the internal name of the Gregorian calendar.

Returns the first date of the Gregorian year.

Returns the month november of the Gregorian calendar.

Returns the month october of the Gregorian calendar.

Returns the fixed date of Pentecost of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

Returns the quarter of a fixed day or a Gregorian date.

Returns a list of the quarters of the Gregorian calendar.

Returns the distance between two Gregorian dates as a range of fixed days.

Returns the weekday saturday of the Gregorian calendar.

Returns the month september of the Gregorian calendar.

Returns the first official use of the Gregorian calendar.

Returns the start of the day in the Gregorian calendar.

Returns the first day of the month given by a fixed day or Gregorian date.

Returns the first day of the month given by the Gregorian year and month.

Returns the first day of the quarter given by a fixed day or a Gregorian date.

Returns the first day of the quarter given by the Gregorian year and quarter.

Returns the start of the week of the fixed day or Gregorian date.

Returns the first day of the Gregorian year given by a fixed day or a Gregorian date.

Returns the weekday sunday of the Gregorian calendar.

Returns the weekday thursday of the Gregorian calendar.

Converts a Gregorian date into the equivalent date of the other_calendar.

Converts a Gregorian date tuple into a fixed day.

Converts a Gregorian date given by year, month, day into a fixed day.

Converts a Gregorian date into the equivalent Julian Day.

Converts a Gregorian date given by year, month, day into the equivalent Julian Day.

Converts a Gregorian date into the equivalent RataDie date.

Converts a Gregorian date given by year, month, day into the equivalent RataDie date.

Converts a Gregorian date into the equivalent Unix date.

Converts a Gregorian date given by year, month, day into the equivalent Unix date.

Returns the current date either as a fixed day or a Gregorian date.

Returns the weekday tuesday of the Gregorian calendar.

Returns the fixed date of Friday the 13th (first) of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

Returns the weekday wednesday of the Gregorian calendar.

Returns the weekday of a fixed day or a Gregorian date.

Returns a list of the weekdays of the Gregorian calendar.

Returns the year field of a Gregorian date.

Returns the last date of the Gregorian year.

Link to this section Types

Specs

fixed() :: integer()

Specs

gregorian_date() :: {gregorian_year(), gregorian_month(), gregorian_day()}

Specs

gregorian_day() :: 1..31

Specs

gregorian_month() :: 1..12

Specs

gregorian_year() :: integer()

Specs

t() :: gregorian_date()

Link to this section Functions

Link to this function

add_days(cal_date, days, type \\ :fixed)

View Source

Specs

add_days(fixed() | gregorian_date(), integer(), :fixed | :date) ::
  fixed() | gregorian_date()

Adds the number of days to a fixed day or Gregorian date.

If days is negative, the days will be subtracted.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.add_days(730739, 100)
  730839
  iex>Elixir.Gregorian.add_days(730739, -100)
  730639

  iex>Elixir.Gregorian.add_days(730739, 100, :fixed)
  730839
  iex>Elixir.Gregorian.add_days(730739, -100, :fixed)
  730639

  iex>Elixir.Gregorian.add_days(730739, 100, :date)
  {2001, 12, 20}
  iex>Elixir.Gregorian.add_days(730739, -100, :date)
  {2001, 6, 3}

  iex>Elixir.Gregorian.add_days({2001, 9, 11}, 100)
  730839
  iex>Elixir.Gregorian.add_days({2001, 9, 11}, -100)
  730639

  iex>Elixir.Gregorian.add_days({2001, 9, 11}, 100, :fixed)
  730839
  iex>Elixir.Gregorian.add_days({2001, 9, 11}, -100, :fixed)
  730639

  iex>Elixir.Gregorian.add_days({2001, 9, 11}, 100, :date)
  {2001, 12, 20}
  iex>Elixir.Gregorian.add_days({2001, 9, 11}, -100, :date)
  {2001, 6, 3}
Link to this function

add_months(cal_date, months, type \\ :fixed)

View Source

Specs

add_months(fixed() | gregorian_date(), integer(), :fixed | :date) ::
  fixed() | gregorian_date()

Adds the number of months to a fixed day or Gregorian date.

If months is negative, the months will be subtracted.

Because of the different lengths of months the result is calculated using the average length of a month; so the day of the base date and the day of the result may vary.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.add_months(730739, 3)
  730830
  iex>Elixir.Gregorian.add_months(730739, -3)
  730647

  iex>Elixir.Gregorian.add_months(730739, 3, :fixed)
  730830
  iex>Elixir.Gregorian.add_months(730739, -3, :fixed)
  730647

  iex>Elixir.Gregorian.add_months(730739, 3, :date)
  {2001, 12, 11}
  iex>Elixir.Gregorian.add_months(730739, -3, :date)
  {2001, 6, 11}

  iex>Elixir.Gregorian.add_months({2001, 9, 11}, 3)
  730830
  iex>Elixir.Gregorian.add_months({2001, 9, 11}, -3)
  730647

  iex>Elixir.Gregorian.add_months({2001, 9, 11}, 3, :fixed)
  730830
  iex>Elixir.Gregorian.add_months({2001, 9, 11}, -3, :fixed)
  730647

  iex>Elixir.Gregorian.add_months({2001, 9, 11}, 3, :date)
  {2001, 12, 11}
  iex>Elixir.Gregorian.add_months({2001, 9, 11}, -3, :date)
  {2001, 6, 11}
Link to this function

add_quarters(cal_date, quarters, type \\ :fixed)

View Source

Specs

add_quarters(fixed() | gregorian_date(), integer(), :fixed | :date) ::
  fixed() | gregorian_date()

Adds the number of quarters to a fixed day or Gregorian date.

If quarters is negative, the quarters will be subtracted.

Because of the different lengths of quarters the result is calculated using the average length of a quarter; so day of the base date and the day of the result may vary.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.add_quarters(730739, 3)
  731012
  iex>Elixir.Gregorian.add_quarters(730739, -3)
  730465

  iex>Elixir.Gregorian.add_quarters(730739, 3, :fixed)
  731012
  iex>Elixir.Gregorian.add_quarters(730739, -3, :fixed)
  730465

  iex>Elixir.Gregorian.add_quarters(730739, 3, :date)
  {2002, 6, 11}
  iex>Elixir.Gregorian.add_quarters(730739, -3, :date)
  {2000, 12, 11}

  iex>Elixir.Gregorian.add_quarters({2001, 9, 11}, 3)
  731012
  iex>Elixir.Gregorian.add_quarters({2001, 9, 11}, -3)
  730465

  iex>Elixir.Gregorian.add_quarters({2001, 9, 11}, 3, :fixed)
  731012
  iex>Elixir.Gregorian.add_quarters({2001, 9, 11}, -3, :fixed)
  730465

  iex>Elixir.Gregorian.add_quarters({2001, 9, 11}, 3, :date)
  {2002, 6, 11}
  iex>Elixir.Gregorian.add_quarters({2001, 9, 11}, -3, :date)
  {2000, 12, 11}
Link to this function

add_weeks(cal_date, weeks, type \\ :fixed)

View Source

Specs

add_weeks(fixed() | gregorian_date(), integer(), :fixed | :date) ::
  fixed() | gregorian_date()

Adds the number of weeks to a fixed day or Gregorian date.

If weeks is negative, the weeks will be subtracted.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.add_weeks(730739, 3)
  730760
  iex>Elixir.Gregorian.add_weeks(730739, -3)
  730718

  iex>Elixir.Gregorian.add_weeks(730739, 3, :fixed)
  730760
  iex>Elixir.Gregorian.add_weeks(730739, -3, :fixed)
  730718

  iex>Elixir.Gregorian.add_weeks(730739, 3, :date)
  {2001, 10, 2}
  iex>Elixir.Gregorian.add_weeks(730739, -3, :date)
  {2001, 8, 21}

  iex>Elixir.Gregorian.add_weeks({2001, 9, 11}, 3)
  730760
  iex>Elixir.Gregorian.add_weeks({2001, 9, 11}, -3)
  730718

  iex>Elixir.Gregorian.add_weeks({2001, 9, 11}, 3, :fixed)
  730760
  iex>Elixir.Gregorian.add_weeks({2001, 9, 11}, -3, :fixed)
  730718

  iex>Elixir.Gregorian.add_weeks({2001, 9, 11}, 3, :date)
  {2001, 10, 2}
  iex>Elixir.Gregorian.add_weeks({2001, 9, 11}, -3, :date)
  {2001, 8, 21}
Link to this function

add_years(cal_date, years, type \\ :fixed)

View Source

Specs

add_years(fixed() | gregorian_date(), integer(), :fixed | :date) ::
  fixed() | gregorian_date()

Adds the number of years to a fixed year or Gregorian date.

Because of the different lengths of years the result is calculated using the average length of a year; so the result will not always have the same day of the month as the base date.

If years is negative, the years will be subtracted.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.add_years(730739, 3)
  731834
  iex>Elixir.Gregorian.add_years(730739, -3)
  729643

  iex>Elixir.Gregorian.add_years(730739, 3, :fixed)
  731834
  iex>Elixir.Gregorian.add_years(730739, -3, :fixed)
  729643

  iex>Elixir.Gregorian.add_years(730739, 3, :date)
  {2004, 9, 10}
  iex>Elixir.Gregorian.add_years(730739, -3, :date)
  {1998, 9, 11}

  iex>Elixir.Gregorian.add_years({2001, 9, 11}, 3)
  731834
  iex>Elixir.Gregorian.add_years({2001, 9, 11}, -3)
  729643

  iex>Elixir.Gregorian.add_years({2001, 9, 11}, 3, :fixed)
  731834
  iex>Elixir.Gregorian.add_years({2001, 9, 11}, -3, :fixed)
  729643

  iex>Elixir.Gregorian.add_years({2001, 9, 11}, 3, :date)
  {2004, 9, 10}
  iex>Elixir.Gregorian.add_years({2001, 9, 11}, -3, :date)
  {1998, 9, 11}

Specs

advent(gregorian_year()) :: fixed() | gregorian_date()

Returns the fixed date of Advent Sunday of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Example

  iex>Elixir.Gregorian.advent(2001)
  {2001, 12, 2}

Specs

april(:integer | :name) :: integer()

Returns the month april of the Gregorian calendar.

The type parameter determines the type of the returned month:

  • :integer returns the number of the month (default),
  • :name returns the name of the month.

Examples

  iex>Elixir.Gregorian.april()
  4
  iex>Elixir.Gregorian.april(:integer)
  4
  iex>Elixir.Gregorian.april(:name)
  "April"

Specs

as_date(fixed() | gregorian_date()) :: gregorian_date()

Returns a fixed day or Gregorian date as a Gregorian date.

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.Gregorian.as_date(730739)
  {2001, 9, 11}
  iex>Elixir.Gregorian.as_date({2001, 9, 11})
  {2001, 9, 11}

Specs

as_fixed(fixed() | gregorian_date()) :: fixed()

Returns a fixed day or Gregorian date as a fixed day.

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.Gregorian.as_fixed(730739)
  730739
  iex>Elixir.Gregorian.as_fixed({2001, 9, 11})
  730739
Link to this function

as_type(cal_date, type \\ :fixed)

View Source

Specs

as_type(fixed() | gregorian_date(), :fixed | :date) ::
  fixed() | gregorian_date()

Returns a fixed day or Gregorian date either as a fixed day or a Gregorian date.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.as_type(730739)
  730739
  iex>Elixir.Gregorian.as_type(730739, :fixed)
  730739
  iex>Elixir.Gregorian.as_type(730739, :date)
  {2001, 9, 11}
  iex>Elixir.Gregorian.as_type({2001, 9, 11})
  730739
  iex>Elixir.Gregorian.as_type({2001, 9, 11}, :fixed)
  730739
  iex>Elixir.Gregorian.as_type({2001, 9, 11}, :date)
  {2001, 9, 11}
Link to this function

august(type \\ :integer)

View Source

Specs

august(:integer | :name) :: integer()

Returns the month august of the Gregorian calendar.

The type parameter determines the type of the returned month:

  • :integer returns the number of the month (default),
  • :name returns the name of the month.

Examples

  iex>Elixir.Gregorian.august()
  8
  iex>Elixir.Gregorian.august(:integer)
  8
  iex>Elixir.Gregorian.august(:name)
  "August"
Link to this function

calixir_api(type \\ :atom)

View Source

Returns a list of the Calixir functions of the Gregorian calendar.

The type parameter determines the type of the returned Calixir function:

  • :atom returns the internal names of the functions (default),
  • :spec returns the complete specifications of the functions.

Examples

  iex>Elixir.Gregorian.calixir_api()
  [:gregorian_epoch, :gregorian_leap_year?, :fixed_from_gregorian, :gregorian_new_year, :gregorian_year_end, :gregorian_year_range, :gregorian_year_from_fixed, :gregorian_from_fixed, :gregorian_date_difference, :day_number, :days_remaining, :last_day_of_gregorian_month, :nth_kday, :first_kday, :last_kday, :unlucky_fridays_in_range]
  iex>Elixir.Gregorian.calixir_api(:atom)
  [:gregorian_epoch, :gregorian_leap_year?, :fixed_from_gregorian, :gregorian_new_year, :gregorian_year_end, :gregorian_year_range, :gregorian_year_from_fixed, :gregorian_from_fixed, :gregorian_date_difference, :day_number, :days_remaining, :last_day_of_gregorian_month, :nth_kday, :first_kday, :last_kday, :unlucky_fridays_in_range]
  iex>Elixir.Gregorian.calixir_api(:fun_specs)
  [[:gregorian_epoch, []], [:gregorian_leap_year?, [:year]], [:fixed_from_gregorian, [:year, :month, :day]], [:gregorian_new_year, [:year]], [:gregorian_year_end, [:year]], [:gregorian_year_range, [:year]], [:gregorian_year_from_fixed, [:fixed]], [:gregorian_from_fixed, [:fixed]], [:gregorian_date_difference, [:date1, :date2]], [:day_number, [:date]], [:days_remaining, [:date]], [:last_day_of_gregorian_month, [:year, :month]], [:nth_kday, [:n, :k, :date]], [:first_kday, [1, :k, :date]], [:last_kday, [-1, :k, :date]], [:unlucky_fridays_in_range, [:a, :b]]]
Link to this function

christmas(gregorian_year)

View Source

Specs

christmas(gregorian_year()) :: fixed() | gregorian_date()

Returns the fixed date of Christmas of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Example

  iex>Elixir.Gregorian.christmas(2001)
  {2001, 12, 25}

Specs

compare(gregorian_date(), gregorian_date()) :: :lt | :eq | :gt

Compares two Gregorian dates and returns...

  • :lt if date1 is smaller (= earlier) than date2,
  • :eq if date1 is equal date2,
  • :gt if date1 is larger (= later) than date2.

Examples

  iex>Elixir.Gregorian.compare({2001, 9, 11}, {2001, 9, 11})
  :eq
  iex>Elixir.Gregorian.compare({2001, 9, 11}, {2001, 12, 20})
  :lt
  iex>Elixir.Gregorian.compare({2001, 12, 20}, {2001, 9, 11})
  :gt

Specs

Returns a Gregorian date from its fields year, month, day.

Example

  iex>Elixir.Gregorian.date(2001, 9, 11)
  {2001, 9, 11}
Link to this function

date_diff(cal_date1, cal_date2)

View Source

Specs

date_diff(fixed() | gregorian_date(), fixed() | gregorian_date()) :: integer()

Returns the difference (= number of days) between two Gregorian dates.

The dates can be given as fixed days or Gregorian dates in arbitrary combination. The difference is calculated by date2 - date1.

If cal_date2 is larger (= later) than cal_date1 the result is positive.

If cal_date2 is smaller (= earlier) than cal_date1 the result is negative.

Examples

  iex>Elixir.Gregorian.date_diff(730739, 730839)
  100
  iex>Elixir.Gregorian.date_diff(730839, 730739)
  -100
  iex>Elixir.Gregorian.date_diff({2001, 9, 11}, {2001, 12, 20})
  100
  iex>Elixir.Gregorian.date_diff({2001, 12, 20}, {2001, 9, 11})
  -100
  iex>Elixir.Gregorian.date_diff(730739, {2001, 12, 20})
  100
  iex>Elixir.Gregorian.date_diff({2001, 9, 11}, 730839)
  100
Link to this function

day(cal_date, type \\ :value)

View Source

Specs

day(fixed() | gregorian_date(), :atom | :index | :name | :value) ::
  :atom | integer() | String.t() | number()

Returns the day field of a Gregorian date.

The type parameter determines the type of the returned day:

  • :atom returns the internal name of day,
  • :index returns the position of the day field within the date,
  • :name returns the common name of the day,
  • :value returns the value of the day (default).

Examples

  iex>Elixir.Gregorian.day(730739)
  11
  iex>Elixir.Gregorian.day(730739, :atom)
  :day
  iex>Elixir.Gregorian.day(730739, :index)
  2
  iex>Elixir.Gregorian.day(730739, :name)
  "Day"
  iex>Elixir.Gregorian.day(730739, :value)
  11

  iex>Elixir.Gregorian.day({2001, 9, 11})
  11
  iex>Elixir.Gregorian.day({2001, 9, 11}, :atom)
  :day
  iex>Elixir.Gregorian.day({2001, 9, 11}, :index)
  2
  iex>Elixir.Gregorian.day({2001, 9, 11}, :name)
  "Day"
  iex>Elixir.Gregorian.day({2001, 9, 11}, :value)
  11

Specs

day_of_month(fixed() | gregorian_date()) :: integer()

Returns the ordinal day number of a fixed day or Gregorian date in the corresponding month.

Examples

  iex>Elixir.Gregorian.day_of_month(730739)
  11
  iex>Elixir.Gregorian.day_of_month({2001, 9, 11})
  11
Link to this function

day_of_quarter(cal_date)

View Source

Specs

day_of_quarter(fixed() | gregorian_date()) :: integer()

Returns the ordinal day number of a fixed day or Gregorian date in the corresponding quarter.

Examples

  iex>Elixir.Gregorian.day_of_quarter(730739)
  73
  iex>Elixir.Gregorian.day_of_quarter({2001, 9, 11})
  73

Specs

day_of_week(fixed() | gregorian_date()) :: integer()

Returns the ordinal day number of a fixed day or Gregorian date in the corresponding week.

Examples

  iex>Elixir.Gregorian.day_of_week(730739)
  2
  iex>Elixir.Gregorian.day_of_week({2001, 9, 11})
  2

Specs

day_of_year(fixed() | gregorian_date()) :: integer()

Returns the ordinal day number of the fixed day or Gregorian date in the equivalent Gregorian year.

Examples

  iex>Elixir.Gregorian.day_of_year(730739)
  254
  iex>Elixir.Gregorian.day_of_year({2001, 9, 11})
  254
Link to this function

daylight_saving_end(gregorian_year)

View Source

Specs

daylight_saving_end(gregorian_year()) :: fixed() | gregorian_date()

Returns the fixed date of Daylight Saving End of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Example

  iex>Elixir.Gregorian.daylight_saving_end(2001)
  {2001, 11, 4}
Link to this function

daylight_saving_start(gregorian_year)

View Source

Specs

daylight_saving_start(gregorian_year()) :: fixed() | gregorian_date()

Returns the fixed date of Daylight Saving Start of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Example

  iex>Elixir.Gregorian.daylight_saving_start(2001)
  {2001, 3, 11}

Specs

days_in_month(fixed() | gregorian_date()) :: integer()

Returns the number of days in the month of a fixed day or Gregorian date.

Examples

  iex>Elixir.Gregorian.days_in_month(730739)
  30
  iex>Elixir.Gregorian.days_in_month({2001, 9, 11})
  30
Link to this function

days_in_month(year, month)

View Source

Specs

days_in_month(gregorian_year(), gregorian_month()) :: integer()

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

Example

  iex>Elixir.Gregorian.days_in_month(2001, 9)
  30
Link to this function

days_in_quarter(cal_date)

View Source

Specs

days_in_quarter(fixed() | gregorian_date()) :: 90..92

Returns the number of days in the quarter given by a fixed day or Gregorian date.

Examples

  iex>Elixir.Gregorian.days_in_quarter(730739)
  92
  iex>Elixir.Gregorian.days_in_quarter({2001, 9, 11})
  92

Specs

days_in_week() :: integer()

Returns the number of days in a week of the Gregorian calendar.

Example

  iex>Elixir.Gregorian.days_in_week()
  7

Specs

days_in_year(gregorian_year()) :: integer()

Returns the number of days in the Gregorian year.

Examples

  iex>Elixir.Gregorian.days_in_year(2000)
  366
  iex>Elixir.Gregorian.days_in_year(2001)
  365
Link to this function

days_remaining_in_month(cal_date)

View Source

Specs

days_remaining_in_month(fixed() | gregorian_date()) :: integer()

Returns the number of days remaing in the month after a fixed day or Gregorian date.

Examples

  iex>Elixir.Gregorian.days_remaining_in_month(730739)
  19
  iex>Elixir.Gregorian.days_remaining_in_month({2001, 9, 11})
  19
Link to this function

days_remaining_in_quarter(cal_date)

View Source

Specs

days_remaining_in_quarter(fixed() | gregorian_date()) :: 89..91

Returns the number of days remaining in the quarter given by a fixed day or Gregorian date.

Examples

  iex>Elixir.Gregorian.days_remaining_in_quarter(730739)
  19
  iex>Elixir.Gregorian.days_remaining_in_quarter({2001, 9, 11})
  19
Link to this function

days_remaining_in_year(cal_date)

View Source

Specs

days_remaining_in_year(fixed() | gregorian_date()) :: integer()

Returns the number of days remaing after a fixed day or a Gregorian date in the equivalent Gregorian year.

Examples

  iex>Elixir.Gregorian.days_remaining_in_year(730739)
  111
  iex>Elixir.Gregorian.days_remaining_in_year({2001, 9, 11})
  111
Link to this function

december(type \\ :integer)

View Source

Specs

december(:integer | :name) :: integer()

Returns the month december of the Gregorian calendar.

The type parameter determines the type of the returned month:

  • :integer returns the number of the month (default),
  • :name returns the name of the month.

Examples

  iex>Elixir.Gregorian.december()
  12
  iex>Elixir.Gregorian.december(:integer)
  12
  iex>Elixir.Gregorian.december(:name)
  "December"

Specs

easter(gregorian_year()) :: fixed() | gregorian_date()

Returns the fixed date of Easter of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Example

  iex>Elixir.Gregorian.easter(2001)
  {2001, 4, 15}
Link to this function

election_day(gregorian_year)

View Source

Specs

election_day(gregorian_year()) :: fixed() | gregorian_date()

Returns the fixed date of U.S. Election Day of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Example

  iex>Elixir.Gregorian.election_day(2001)
  {2001, 11, 6}
Link to this function

end_of_month(cal_date, type \\ :fixed)

View Source

Specs

end_of_month(fixed() | gregorian_date(), :fixed | :date) ::
  fixed() | gregorian_date()

Returns the last day of the month given by a fixed day or Gregorian date.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.end_of_month(730739)
  730758
  iex>Elixir.Gregorian.end_of_month(730739, :fixed)
  730758
  iex>Elixir.Gregorian.end_of_month(730739, :date)
  {2001, 9, 30}

  iex>Elixir.Gregorian.end_of_month({2001, 9, 30})
  730758
  iex>Elixir.Gregorian.end_of_month({2001, 9, 11}, :fixed)
  730758
  iex>Elixir.Gregorian.end_of_month({2001, 9, 11}, :date)
  {2001, 9, 30}
Link to this function

end_of_month(year, month, type)

View Source

Specs

end_of_month(gregorian_year(), gregorian_month(), :fixed | :date) ::
  fixed() | gregorian_date()

Returns the last day of the month given by the Gregorian year and month.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.end_of_month(2001, 9, :fixed)
  730758
  iex>Elixir.Gregorian.end_of_month(2001, 9, :date)
  {2001, 9, 30}
Link to this function

end_of_quarter(cal_date, type \\ :fixed)

View Source

Specs

end_of_quarter(fixed() | gregorian_date(), :fixed | :date) ::
  fixed() | gregorian_date()

Returns the last day of the quarter given by a fixed day or a Gregorian date.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.end_of_quarter(730739)
  730758
  iex>Elixir.Gregorian.end_of_quarter(730739, :fixed)
  730758
  iex>Elixir.Gregorian.end_of_quarter(730739, :date)
  {2001, 9, 30}

  iex>Elixir.Gregorian.end_of_quarter({2001, 9, 11})
  730758
  iex>Elixir.Gregorian.end_of_quarter({2001, 9, 11}, :fixed)
  730758
  iex>Elixir.Gregorian.end_of_quarter({2001, 9, 11}, :date)
  {2001, 9, 30}
Link to this function

end_of_quarter(year, quarter, type)

View Source

Specs

end_of_quarter(gregorian_year(), 1..4, :fixed | :date) ::
  fixed() | gregorian_date()

Returns the last day of the quarter given by the Gregorian year and quarter.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.end_of_quarter(2001, 3, :fixed)
  730758
  iex>Elixir.Gregorian.end_of_quarter(2001, 3, :date)
  {2001, 9, 30}
Link to this function

end_of_week(cal_date, type \\ :fixed)

View Source

Specs

end_of_week(fixed() | gregorian_date(), :fixed | :date) ::
  fixed() | gregorian_date()

Returns the end of the week of the fixed day or Gregorian date.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.end_of_week(730739)
  730743
  iex>Elixir.Gregorian.end_of_week(730739, :fixed)
  730743
  iex>Elixir.Gregorian.end_of_week(730739, :date)
  {2001, 9, 15}

  iex>Elixir.Gregorian.end_of_week({2001, 9, 11})
  730743
  iex>Elixir.Gregorian.end_of_week({2001, 9, 11}, :fixed)
  730743
  iex>Elixir.Gregorian.end_of_week({2001, 9, 11}, :date)
  {2001, 9, 15}
Link to this function

end_of_year(cal_date, type \\ :fixed)

View Source

Specs

end_of_year(fixed() | gregorian_date(), :fixed | :date) ::
  fixed() | gregorian_date()

Returns the last day of the Gregorian year given by a fixed day or a Gregorian date.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.end_of_year(730739)
  730850
  iex>Elixir.Gregorian.end_of_year(730739, :fixed)
  730850
  iex>Elixir.Gregorian.end_of_year(730739, :date)
  {2001, 12, 31}
Link to this function

epiphany(gregorian_year)

View Source

Specs

epiphany(gregorian_year()) :: fixed() | gregorian_date()

Returns the fixed date of Epiphany of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Example

  iex>Elixir.Gregorian.epiphany(2001)
  {2001, 1, 7}

Specs

epoch() :: number()

Returns the epoch of the Gregorian calendar.

Example

  iex>Elixir.Gregorian.epoch()
  1

Specs

Returns true if Gregorian date1 is equal Gregorian date2, otherwise false.

Examples

  iex>Elixir.Gregorian.eq({2001, 9, 11}, {2001, 9, 11})
  true
  iex>Elixir.Gregorian.eq({2001, 9, 11}, {2001, 12, 20})
  false
  iex>Elixir.Gregorian.eq({2001, 12, 20}, {2001, 9, 11})
  false
Link to this function

february(type \\ :integer)

View Source

Specs

february(:integer | :name) :: integer()

Returns the month february of the Gregorian calendar.

The type parameter determines the type of the returned month:

  • :integer returns the number of the month (default),
  • :name returns the name of the month.

Examples

  iex>Elixir.Gregorian.february()
  2
  iex>Elixir.Gregorian.february(:integer)
  2
  iex>Elixir.Gregorian.february(:name)
  "February"

Specs

field_atom(integer()) :: atom()

Returns the name of the field atom in a Gregorian date at field_index.

Examples

  iex>Elixir.Gregorian.field_atom(0)
  :year
  iex>Elixir.Gregorian.field_atom(1)
  :month
  iex>Elixir.Gregorian.field_atom(2)
  :day

Specs

field_atoms() :: [atom()]

Returns a list of the field atoms (names) of a Gregorian date.

Example

  iex>Elixir.Gregorian.field_atoms()
  [:year, :month, :day]

Specs

field_count() :: integer()

Returns the number of fields in a Gregorian date

Example

  iex>Elixir.Gregorian.field_count()
  3

Specs

field_index(atom()) :: integer()

Returns the index (= position) of the field_atom in a Gregorian date.

Examples

  iex>Elixir.Gregorian.field_index(:year)
  0
  iex>Elixir.Gregorian.field_index(:month)
  1
  iex>Elixir.Gregorian.field_index(:day)
  2
Link to this function

friday(type \\ :integer)

View Source

Specs

friday(:integer | :name) :: integer()

Returns the weekday friday of the Gregorian calendar.

The type parameter determines the type of the returned weekday:

  • :integer returns the number of the weekday (default),
  • :name returns the name of the weekday.

Examples

  iex>Elixir.Gregorian.friday()
  5
  iex>Elixir.Gregorian.friday(:integer)
  5
  iex>Elixir.Gregorian.friday(:name)
  "Friday"
Link to this function

from_date(other_date, other_calendar)

View Source

Specs

from_date(tuple(), module()) :: gregorian_date()
from_date(tuple(), module()) :: {:error, String.t()}

Converts the other_date of the other_calendar into the equivalent date of the Gregorian calendar.

Example

  iex>Elixir.Gregorian.from_date({2001, 9, 11}, Gregorian)
  {2001, 9, 11}

Specs

from_fixed(fixed()) :: gregorian_date()

Converts a fixed day to a Gregorian date.

Example

  iex>Elixir.Gregorian.from_fixed(730739)
  {2001, 9, 11}

Specs

from_jd(tuple() | number()) :: gregorian_date()

Converts a Julian Day into the equivalent Gregorian date.

The Julian Day can be given as a tuple or by a Julian day.

Examples

  iex>Elixir.Gregorian.from_jd({2452163.5})
  {2001, 9, 11}
  iex>Elixir.Gregorian.from_jd(2452163.5)
  {2001, 9, 11}

Specs

from_rata_die(tuple() | integer()) :: gregorian_date()

Converts a RataDie date into the equivalent Gregorian date.

The RataDie date can be given as a tuple or by a RataDie rd.

Examples

  iex>Elixir.Gregorian.from_rata_die({730739})
  {2001, 9, 11}
  iex>Elixir.Gregorian.from_rata_die(730739)
  {2001, 9, 11}

Specs

from_unix(tuple() | integer()) :: gregorian_date()

Converts a Unix date into the equivalent Gregorian date.

The Unix date can be given as a tuple or by Unix seconds.

Examples

  iex>Elixir.Gregorian.from_unix({1000166400})
  {2001, 9, 11}
  iex>Elixir.Gregorian.from_unix(1000166400)
  {2001, 9, 11}

Specs

Returns true if Gregorian date1 is greater (= later) than or equal Gregorian date2, otherwise false.

Examples

  iex>Elixir.Gregorian.ge({2001, 9, 11}, {2001, 9, 11})
  true
  iex>Elixir.Gregorian.ge({2001, 9, 11}, {2001, 12, 20})
  false
  iex>Elixir.Gregorian.ge({2001, 12, 20}, {2001, 9, 11})
  true

Specs

Returns true if Gregorian date1 is greater (= later) than Gregorian date2, otherwise false.

Examples

  iex>Elixir.Gregorian.gt({2001, 9, 11}, {2001, 9, 11})
  false
  iex>Elixir.Gregorian.gt({2001, 9, 11}, {2001, 12, 20})
  false
  iex>Elixir.Gregorian.gt({2001, 12, 20}, {2001, 9, 11})
  true

Returns a list of the holidays of the Gregorian calendar.

The type parameter determines the type of the returned holidays:

  • :atom returns the internal names of the holidays,
  • :name returns the common names of the holidays (default).

Examples

  iex>Elixir.Gregorian.holidays()
  ["U.S. Independence Day", "U.S. Labor Day", "U.S. Memorial Day", "U.S. Election Day", "Daylight Saving Start", "Daylight Saving End", "Christmas", "Advent Sunday", "Epiphany", "Friday the 13th (first)", "Easter", "Pentecost"]
  iex>Elixir.Gregorian.holidays(:atom)
  [:independence_day, :labor_day, :memorial_day, :election_day, :daylight_saving_start, :daylight_saving_end, :christmas, :advent, :epiphany, :unlucky_fridays, :easter, :pentecost]
  iex>Elixir.Gregorian.holidays(:name)
  ["U.S. Independence Day", "U.S. Labor Day", "U.S. Memorial Day", "U.S. Election Day", "Daylight Saving Start", "Daylight Saving End", "Christmas", "Advent Sunday", "Epiphany", "Friday the 13th (first)", "Easter", "Pentecost"]

Specs

i(:integer | :name) :: integer()

Returns the quarter i of the Gregorian calendar.

The type parameter determines the type of the returned quarter:

  • :integer returns the number of the quarter (default),
  • :name returns the name of the quarter.

Examples

  iex>Elixir.Gregorian.i()
  1
  iex>Elixir.Gregorian.i(:integer)
  1
  iex>Elixir.Gregorian.i(:name)
  "I"

Specs

ii(:integer | :name) :: integer()

Returns the quarter ii of the Gregorian calendar.

The type parameter determines the type of the returned quarter:

  • :integer returns the number of the quarter (default),
  • :name returns the name of the quarter.

Examples

  iex>Elixir.Gregorian.ii()
  2
  iex>Elixir.Gregorian.ii(:integer)
  2
  iex>Elixir.Gregorian.ii(:name)
  "II"

Specs

iii(:integer | :name) :: integer()

Returns the quarter iii of the Gregorian calendar.

The type parameter determines the type of the returned quarter:

  • :integer returns the number of the quarter (default),
  • :name returns the name of the quarter.

Examples

  iex>Elixir.Gregorian.iii()
  3
  iex>Elixir.Gregorian.iii(:integer)
  3
  iex>Elixir.Gregorian.iii(:name)
  "III"
Link to this function

independence_day(gregorian_year)

View Source

Specs

independence_day(gregorian_year()) :: fixed() | gregorian_date()

Returns the fixed date of U.S. Independence Day of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Example

  iex>Elixir.Gregorian.independence_day(2001)
  {2001, 7, 4}

Specs

iv(:integer | :name) :: integer()

Returns the quarter iv of the Gregorian calendar.

The type parameter determines the type of the returned quarter:

  • :integer returns the number of the quarter (default),
  • :name returns the name of the quarter.

Examples

  iex>Elixir.Gregorian.iv()
  4
  iex>Elixir.Gregorian.iv(:integer)
  4
  iex>Elixir.Gregorian.iv(:name)
  "IV"
Link to this function

january(type \\ :integer)

View Source

Specs

january(:integer | :name) :: integer()

Returns the month january of the Gregorian calendar.

The type parameter determines the type of the returned month:

  • :integer returns the number of the month (default),
  • :name returns the name of the month.

Examples

  iex>Elixir.Gregorian.january()
  1
  iex>Elixir.Gregorian.january(:integer)
  1
  iex>Elixir.Gregorian.january(:name)
  "January"

Specs

july(:integer | :name) :: integer()

Returns the month july of the Gregorian calendar.

The type parameter determines the type of the returned month:

  • :integer returns the number of the month (default),
  • :name returns the name of the month.

Examples

  iex>Elixir.Gregorian.july()
  7
  iex>Elixir.Gregorian.july(:integer)
  7
  iex>Elixir.Gregorian.july(:name)
  "July"

Specs

june(:integer | :name) :: integer()

Returns the month june of the Gregorian calendar.

The type parameter determines the type of the returned month:

  • :integer returns the number of the month (default),
  • :name returns the name of the month.

Examples

  iex>Elixir.Gregorian.june()
  6
  iex>Elixir.Gregorian.june(:integer)
  6
  iex>Elixir.Gregorian.june(:name)
  "June"

Specs

keyword() :: atom()

Returns the internal keyword of the Gregorian calendar.

Example

  iex>Elixir.Gregorian.keyword()
  :gregorian
Link to this function

labor_day(gregorian_year)

View Source

Specs

labor_day(gregorian_year()) :: fixed() | gregorian_date()

Returns the fixed date of U.S. Labor Day of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Example

  iex>Elixir.Gregorian.labor_day(2001)
  {2001, 9, 3}
Link to this function

last_month_of_year(cal_date, type \\ :integer)

View Source

Specs

last_month_of_year(fixed() | gregorian_date(), :fixed | :date) ::
  fixed() | gregorian_date()

Returns the last month of the Gregorian year given by a fixed day or a Gregorian date.

The type parameter determines the type of the returned month:

  • :atom returns the internal name of the month,
  • :integer returns the number of the month (default),
  • :name returns the common name of the month.

Examples

  iex>Elixir.Gregorian.last_month_of_year(730739)
  12
  iex>Elixir.Gregorian.last_month_of_year(730739, :atom)
  :december
  iex>Elixir.Gregorian.last_month_of_year(730739, :integer)
  12
  iex>Elixir.Gregorian.last_month_of_year(730739, :name)
  "December"

  iex>Elixir.Gregorian.last_month_of_year({2001, 9, 11})
  12
  iex>Elixir.Gregorian.last_month_of_year({2001, 9, 11}, :atom)
  :december
  iex>Elixir.Gregorian.last_month_of_year({2001, 9, 11}, :integer)
  12
  iex>Elixir.Gregorian.last_month_of_year({2001, 9, 11}, :name)
  "December"

Specs

Returns true if Gregorian date1 is smaller (= earlier) than or equal Gregorian date2, otherwise false.

Examples

  iex>Elixir.Gregorian.le({2001, 9, 11}, {2001, 9, 11})
  true
  iex>Elixir.Gregorian.le({2001, 9, 11}, {2001, 12, 20})
  true
  iex>Elixir.Gregorian.le({2001, 12, 20}, {2001, 9, 11})
  false

Specs

leap_year?(gregorian_year()) :: boolean()

Returns true if the Gregorian year is a leap year, otherwise false.

Examples

  iex>Elixir.Gregorian.leap_year?(2000)
  true
  iex>Elixir.Gregorian.leap_year?(2001)
  false
  iex>Elixir.Gregorian.leap_year?(2002)
  false
  iex>Elixir.Gregorian.leap_year?(2003)
  false

Specs

Returns true if Gregorian date1 is smaller (= earlier) than Gregorian date2, otherwise false.

Examples

  iex>Elixir.Gregorian.lt({2001, 9, 11}, {2001, 9, 11})
  false
  iex>Elixir.Gregorian.lt({2001, 9, 11}, {2001, 12, 20})
  true
  iex>Elixir.Gregorian.lt({2001, 12, 20}, {2001, 9, 11})
  false

Specs

march(:integer | :name) :: integer()

Returns the month march of the Gregorian calendar.

The type parameter determines the type of the returned month:

  • :integer returns the number of the month (default),
  • :name returns the name of the month.

Examples

  iex>Elixir.Gregorian.march()
  3
  iex>Elixir.Gregorian.march(:integer)
  3
  iex>Elixir.Gregorian.march(:name)
  "March"

Specs

may(:integer | :name) :: integer()

Returns the month may of the Gregorian calendar.

The type parameter determines the type of the returned month:

  • :integer returns the number of the month (default),
  • :name returns the name of the month.

Examples

  iex>Elixir.Gregorian.may()
  5
  iex>Elixir.Gregorian.may(:integer)
  5
  iex>Elixir.Gregorian.may(:name)
  "May"

Specs

mean_month() :: number()

Returns the average length of a Gregorian month.

Example

  iex>Elixir.Gregorian.mean_month()
  30.436875

Specs

mean_quarter() :: number()

Returns the average length of a Gregorian quarter.

Example

  iex>Elixir.Gregorian.mean_quarter()
  91.310625

Specs

mean_year() :: number()

Returns the average length of a Gregorian year.

Example

  iex>Elixir.Gregorian.mean_year()
  365.2425
Link to this function

memorial_day(gregorian_year)

View Source

Specs

memorial_day(gregorian_year()) :: fixed() | gregorian_date()

Returns the fixed date of U.S. Memorial Day of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Example

  iex>Elixir.Gregorian.memorial_day(2001)
  {2001, 5, 28}

Specs

module() :: module()

Returns the module of the Gregorian calendar.

Example

  iex>Elixir.Gregorian.module()
  Gregorian
Link to this function

monday(type \\ :integer)

View Source

Specs

monday(:integer | :name) :: integer()

Returns the weekday monday of the Gregorian calendar.

The type parameter determines the type of the returned weekday:

  • :integer returns the number of the weekday (default),
  • :name returns the name of the weekday.

Examples

  iex>Elixir.Gregorian.monday()
  1
  iex>Elixir.Gregorian.monday(:integer)
  1
  iex>Elixir.Gregorian.monday(:name)
  "Monday"
Link to this function

month(cal_date, type \\ :value)

View Source

Specs

month(fixed() | gregorian_date(), :atom | :index | :name | :value) ::
  :atom | integer() | String.t() | number()

Returns the month field of a Gregorian date.

The type parameter determines the type of the returned month:

  • :atom returns the internal name of month,
  • :index returns the position of the month field within the date,
  • :name returns the common name of the month,
  • :value returns the value of the month (default).

Examples

  iex>Elixir.Gregorian.month(730739)
  9
  iex>Elixir.Gregorian.month(730739, :atom)
  :month
  iex>Elixir.Gregorian.month(730739, :index)
  1
  iex>Elixir.Gregorian.month(730739, :name)
  "Month"
  iex>Elixir.Gregorian.month(730739, :value)
  9

  iex>Elixir.Gregorian.month({2001, 9, 11})
  9
  iex>Elixir.Gregorian.month({2001, 9, 11}, :atom)
  :month
  iex>Elixir.Gregorian.month({2001, 9, 11}, :index)
  1
  iex>Elixir.Gregorian.month({2001, 9, 11}, :name)
  "Month"
  iex>Elixir.Gregorian.month({2001, 9, 11}, :value)
  9

Specs

months(:atom | :integer | :name) :: [integer() | atom() | String.t()]

Returns a list of the months of the Gregorian calendar.

The type parameter determines the type of the returned months:

  • :integer returns the numbers of the months,
  • :atom returns the internal names of the months,
  • :name returns the common names of the months (default).

Examples

  iex>Elixir.Gregorian.months()
  ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
  iex>Elixir.Gregorian.months(:integer)
  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
  iex>Elixir.Gregorian.months(:atom)
  [:january, :february, :march, :april, :may, :june, :july, :august, :september, :october, :november, :december]
  iex>Elixir.Gregorian.months(:name)
  ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

Specs

months_in_year(gregorian_year()) :: integer()

Returns the number of months in the Gregorian year.

Example

  iex>Elixir.Gregorian.months_in_year(730739)
  12

Specs

name() :: atom()

Returns the internal name of the Gregorian calendar.

Example

  iex>Elixir.Gregorian.name()
  "Gregorian"
Link to this function

new_year(year, type \\ :fixed)

View Source

Specs

new_year(gregorian_year(), :fixed | :date) :: fixed() | gregorian_date()

Returns the first date of the Gregorian year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.new_year(2001)
  730486
  iex>Elixir.Gregorian.new_year(2001, :fixed)
  730486
  iex>Elixir.Gregorian.new_year(2001, :date)
  {2001, 1, 1}
Link to this function

november(type \\ :integer)

View Source

Specs

november(:integer | :name) :: integer()

Returns the month november of the Gregorian calendar.

The type parameter determines the type of the returned month:

  • :integer returns the number of the month (default),
  • :name returns the name of the month.

Examples

  iex>Elixir.Gregorian.november()
  11
  iex>Elixir.Gregorian.november(:integer)
  11
  iex>Elixir.Gregorian.november(:name)
  "November"
Link to this function

october(type \\ :integer)

View Source

Specs

october(:integer | :name) :: integer()

Returns the month october of the Gregorian calendar.

The type parameter determines the type of the returned month:

  • :integer returns the number of the month (default),
  • :name returns the name of the month.

Examples

  iex>Elixir.Gregorian.october()
  10
  iex>Elixir.Gregorian.october(:integer)
  10
  iex>Elixir.Gregorian.october(:name)
  "October"
Link to this function

pentecost(gregorian_year)

View Source

Specs

pentecost(gregorian_year()) :: fixed() | gregorian_date()

Returns the fixed date of Pentecost of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Example

  iex>Elixir.Gregorian.pentecost(2001)
  {2001, 6, 3}
Link to this function

quarter(cal_date, type \\ :integer)

View Source

Returns the quarter of a fixed day or a Gregorian date.

The type parameter determines the type of the returned quarter:

  • :atom returns the atom of the quarter,
  • :integer returns the number of the quarter (default),
  • :name returns the name of the quarter.

Examples

  iex>Elixir.Gregorian.quarter(730739)
  3
  iex>Elixir.Gregorian.quarter(730739, :atom)
  :iii
  iex>Elixir.Gregorian.quarter(730739, :integer)
  3
  iex>Elixir.Gregorian.quarter(730739, :name)
  "III"
  iex>Elixir.Gregorian.quarter({2001, 9, 11})
  3
  iex>Elixir.Gregorian.quarter({2001, 9, 11}, :atom)
  :iii
  iex>Elixir.Gregorian.quarter({2001, 9, 11}, :integer)
  3
  iex>Elixir.Gregorian.quarter({2001, 9, 11}, :name)
  "III"

Returns a list of the quarters of the Gregorian calendar.

The type parameter determines the type of the returned quarters:

  • :integer returns the numbers of the quarters,
  • :atom returns the internal names of the quarters,
  • :name returns the common names of the quarters (default).

Examples

  iex>Elixir.Gregorian.quarters()
  ["I", "II", "III", "IV"]
  iex>Elixir.Gregorian.quarters(:integer)
  [1, 2, 3, 4]
  iex>Elixir.Gregorian.quarters(:atom)
  [:i, :ii, :iii, :iv]
  iex>Elixir.Gregorian.quarters(:name)
  ["I", "II", "III", "IV"]

Specs

Returns the distance between two Gregorian dates as a range of fixed days.

Example

  iex>Elixir.Gregorian.range({2001, 9, 11}, {2001, 12, 20})
  730739..730839
Link to this function

saturday(type \\ :integer)

View Source

Specs

saturday(:integer | :name) :: integer()

Returns the weekday saturday of the Gregorian calendar.

The type parameter determines the type of the returned weekday:

  • :integer returns the number of the weekday (default),
  • :name returns the name of the weekday.

Examples

  iex>Elixir.Gregorian.saturday()
  6
  iex>Elixir.Gregorian.saturday(:integer)
  6
  iex>Elixir.Gregorian.saturday(:name)
  "Saturday"
Link to this function

september(type \\ :integer)

View Source

Specs

september(:integer | :name) :: integer()

Returns the month september of the Gregorian calendar.

The type parameter determines the type of the returned month:

  • :integer returns the number of the month (default),
  • :name returns the name of the month.

Examples

  iex>Elixir.Gregorian.september()
  9
  iex>Elixir.Gregorian.september(:integer)
  9
  iex>Elixir.Gregorian.september(:name)
  "September"
Link to this function

start_of_calendar(type \\ :fixed)

View Source

Specs

start_of_calendar(:fixed | :date) :: term()

Returns the first official use of the Gregorian calendar.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.start_of_calendar()
  577736
  iex>Elixir.Gregorian.start_of_calendar(:fixed)
  577736
  iex>Elixir.Gregorian.start_of_calendar(:date)
  {1582, 10, 15}

Specs

start_of_day() :: :midnight | :sunset | :sunrise | :noon

Returns the start of the day in the Gregorian calendar.

Possible return values are:

  • :midnight,
  • :noon,
  • :sunrise,
  • :sunset,

Example

  iex>Elixir.Gregorian.start_of_day()
  :midnight
Link to this function

start_of_month(cal_date, type \\ :fixed)

View Source

Specs

start_of_month(fixed() | gregorian_date(), :fixed | :date) ::
  fixed() | gregorian_date()

Returns the first day of the month given by a fixed day or Gregorian date.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.start_of_month(730729)
  730729
  iex>Elixir.Gregorian.start_of_month(730729, :fixed)
  730729
  iex>Elixir.Gregorian.start_of_month(730729, :date)
  {2001, 9, 1}

  iex>Elixir.Gregorian.start_of_month({2001, 9, 1})
  730729
  iex>Elixir.Gregorian.start_of_month({2001, 9, 1}, :fixed)
  730729
  iex>Elixir.Gregorian.start_of_month({2001, 9, 1}, :date)
  {2001, 9, 1}
Link to this function

start_of_month(year, month, type)

View Source

Specs

start_of_month(gregorian_year(), gregorian_month(), :fixed | :date) ::
  fixed() | gregorian_date()

Returns the first day of the month given by the Gregorian year and month.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.start_of_month(2001, 9, :fixed)
  730729
  iex>Elixir.Gregorian.start_of_month(2001, 9, :date)
  {2001, 9, 1}
Link to this function

start_of_quarter(cal_date, type \\ :fixed)

View Source

Specs

start_of_quarter(fixed() | gregorian_date(), :fixed | :date) ::
  fixed() | gregorian_date()

Returns the first day of the quarter given by a fixed day or a Gregorian date.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.start_of_quarter(730739)
  730667
  iex>Elixir.Gregorian.start_of_quarter(730739, :fixed)
  730667
  iex>Elixir.Gregorian.start_of_quarter(730739, :date)
  {2001, 7, 1}

  iex>Elixir.Gregorian.start_of_quarter({2001, 9, 11})
  730667
  iex>Elixir.Gregorian.start_of_quarter({2001, 9, 11}, :fixed)
  730667
  iex>Elixir.Gregorian.start_of_quarter({2001, 9, 11}, :date)
  {2001, 7, 1}
Link to this function

start_of_quarter(year, quarter, type)

View Source

Specs

start_of_quarter(gregorian_year(), 1..4, :fixed | :date) ::
  fixed() | gregorian_date()

Returns the first day of the quarter given by the Gregorian year and quarter.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.start_of_quarter(2001, 3, :fixed)
  730667
  iex>Elixir.Gregorian.start_of_quarter(2001, 3, :date)
  {2001, 7, 1}
Link to this function

start_of_week(cal_date, type \\ :fixed)

View Source

Specs

start_of_week(fixed() | gregorian_date(), :fixed | :date) ::
  fixed() | gregorian_date()

Returns the start of the week of the fixed day or Gregorian date.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.start_of_week(730739)
  730737
  iex>Elixir.Gregorian.start_of_week(730739, :fixed)
  730737
  iex>Elixir.Gregorian.start_of_week(730739, :date)
  {2001, 9, 9}

  iex>Elixir.Gregorian.start_of_week({2001, 9, 11})
  730737
  iex>Elixir.Gregorian.start_of_week({2001, 9, 11}, :fixed)
  730737
  iex>Elixir.Gregorian.start_of_week({2001, 9, 11}, :date)
  {2001, 9, 9}
Link to this function

start_of_year(cal_date, type \\ :fixed)

View Source

Specs

start_of_year(fixed() | gregorian_date(), :fixed | :date) ::
  fixed() | gregorian_date()

Returns the first day of the Gregorian year given by a fixed day or a Gregorian date.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.start_of_year(730739)
  730486
  iex>Elixir.Gregorian.start_of_year(730739, :fixed)
  730486
  iex>Elixir.Gregorian.start_of_year(730739, :date)
  {2001, 1, 1}
Link to this function

sunday(type \\ :integer)

View Source

Specs

sunday(:integer | :name) :: integer()

Returns the weekday sunday of the Gregorian calendar.

The type parameter determines the type of the returned weekday:

  • :integer returns the number of the weekday (default),
  • :name returns the name of the weekday.

Examples

  iex>Elixir.Gregorian.sunday()
  0
  iex>Elixir.Gregorian.sunday(:integer)
  0
  iex>Elixir.Gregorian.sunday(:name)
  "Sunday"
Link to this function

thursday(type \\ :integer)

View Source

Specs

thursday(:integer | :name) :: integer()

Returns the weekday thursday of the Gregorian calendar.

The type parameter determines the type of the returned weekday:

  • :integer returns the number of the weekday (default),
  • :name returns the name of the weekday.

Examples

  iex>Elixir.Gregorian.thursday()
  4
  iex>Elixir.Gregorian.thursday(:integer)
  4
  iex>Elixir.Gregorian.thursday(:name)
  "Thursday"
Link to this function

to_date(date, other_calendar)

View Source

Specs

to_date(gregorian_date(), module()) :: tuple()

Converts a Gregorian date into the equivalent date of the other_calendar.

For the following example to work the Gregorian calendar must be available.

Example

  iex>Elixir.Gregorian.to_date({2001, 9, 11}, Gregorian)
  {2001, 9, 11}

Specs

to_fixed(gregorian_date()) :: fixed()

Converts a Gregorian date tuple into a fixed day.

Example

  iex>Elixir.Gregorian.to_fixed({2001, 9, 11})
  730739
Link to this function

to_fixed(year, month, day)

View Source

Specs

Converts a Gregorian date given by year, month, day into a fixed day.

Example

  iex>Elixir.Gregorian.to_fixed(2001, 9, 11)
  730739

Specs

to_jd(gregorian_date()) :: {number()}

Converts a Gregorian date into the equivalent Julian Day.

Example

  iex>Elixir.Gregorian.to_jd({2001, 9, 11})
  {2452163.5}

Specs

Converts a Gregorian date given by year, month, day into the equivalent Julian Day.

Example

  iex>Elixir.Gregorian.to_jd(2001, 9, 11)
  {2452163.5}

Specs

to_rata_die(gregorian_date()) :: {integer()}

Converts a Gregorian date into the equivalent RataDie date.

Example

  iex>Elixir.Gregorian.to_rata_die({2001, 9, 11})
  {730739}
Link to this function

to_rata_die(year, month, day)

View Source

Specs

to_rata_die(gregorian_year(), gregorian_month(), gregorian_day()) :: {integer()}

Converts a Gregorian date given by year, month, day into the equivalent RataDie date.

Example

  iex>Elixir.Gregorian.to_rata_die(2001, 9, 11)
  {730739}

Specs

to_unix(gregorian_date()) :: {integer()}

Converts a Gregorian date into the equivalent Unix date.

Example

  iex>Elixir.Gregorian.to_unix({2001, 9, 11})
  {1000166400}
Link to this function

to_unix(year, month, day)

View Source

Specs

Converts a Gregorian date given by year, month, day into the equivalent Unix date.

Example

  iex>Elixir.Gregorian.to_unix(2001, 9, 11)
  {1000166400}

Specs

today(:fixed | :date) :: fixed() | gregorian_date()

Returns the current date either as a fixed day or a Gregorian date.

(This cannot be doctested, because today is a moving target.)

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  Elixir.Gregorian.today()
  730739
  Elixir.Gregorian.today(:fixed)
  730739
  Elixir.Gregorian.today(:date)
  {2001, 9, 11}
Link to this function

tuesday(type \\ :integer)

View Source

Specs

tuesday(:integer | :name) :: integer()

Returns the weekday tuesday of the Gregorian calendar.

The type parameter determines the type of the returned weekday:

  • :integer returns the number of the weekday (default),
  • :name returns the name of the weekday.

Examples

  iex>Elixir.Gregorian.tuesday()
  2
  iex>Elixir.Gregorian.tuesday(:integer)
  2
  iex>Elixir.Gregorian.tuesday(:name)
  "Tuesday"
Link to this function

unlucky_fridays(gregorian_year)

View Source

Specs

unlucky_fridays(gregorian_year()) :: fixed() | gregorian_date()

Returns the fixed date of Friday the 13th (first) of the Gregorian calendar in the given gregorian_year or [], if there is no such holiday in that year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Example

  iex>Elixir.Gregorian.unlucky_fridays(2001)
  {2001, 4, 13}
Link to this function

wednesday(type \\ :integer)

View Source

Specs

wednesday(:integer | :name) :: integer()

Returns the weekday wednesday of the Gregorian calendar.

The type parameter determines the type of the returned weekday:

  • :integer returns the number of the weekday (default),
  • :name returns the name of the weekday.

Examples

  iex>Elixir.Gregorian.wednesday()
  3
  iex>Elixir.Gregorian.wednesday(:integer)
  3
  iex>Elixir.Gregorian.wednesday(:name)
  "Wednesday"
Link to this function

weekday(cal_date, type \\ :integer)

View Source

Specs

weekday(fixed() | gregorian_date(), :atom | :integer | :name) ::
  integer() | atom() | String.t()

Returns the weekday of a fixed day or a Gregorian date.

The type parameter determines the type of the returned weekday:

  • :atom returns the internal name of weekday,
  • :integer returns the number of the weekday (default),
  • :name returns the common name of the weekday.

Examples

  iex>Elixir.Gregorian.weekday(730739)
  2
  iex>Elixir.Gregorian.weekday(730739, :integer)
  2
  iex>Elixir.Gregorian.weekday(730739, :atom)
  :tuesday
  iex>Elixir.Gregorian.weekday(730739, :name)
  "Tuesday"

  iex>Elixir.Gregorian.weekday({2001, 9, 11})
  2
  iex>Elixir.Gregorian.weekday({2001, 9, 11}, :integer)
  2
  iex>Elixir.Gregorian.weekday({2001, 9, 11}, :atom)
  :tuesday
  iex>Elixir.Gregorian.weekday({2001, 9, 11}, :name)
  "Tuesday"

Returns a list of the weekdays of the Gregorian calendar.

The type parameter determines the type of the returned weekdays:

  • :integer returns the numbers of the weekdays,
  • :atom returns the internal names of the weekdays,
  • :name returns the common names of the weekdays (default).

Examples

  iex>Elixir.Gregorian.weekdays()
  ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
  iex>Elixir.Gregorian.weekdays(:integer)
  [0, 1, 2, 3, 4, 5, 6]
  iex>Elixir.Gregorian.weekdays(:atom)
  [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
  iex>Elixir.Gregorian.weekdays(:name)
  ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
Link to this function

year(cal_date, type \\ :value)

View Source

Specs

year(fixed() | gregorian_date(), :atom | :index | :name | :value) ::
  :atom | integer() | String.t() | number()

Returns the year field of a Gregorian date.

The type parameter determines the type of the returned year:

  • :atom returns the internal name of year,
  • :index returns the position of the year field within the date,
  • :name returns the common name of the year,
  • :value returns the value of the year (default).

Examples

  iex>Elixir.Gregorian.year(730739)
  2001
  iex>Elixir.Gregorian.year(730739, :atom)
  :year
  iex>Elixir.Gregorian.year(730739, :index)
  0
  iex>Elixir.Gregorian.year(730739, :name)
  "Year"
  iex>Elixir.Gregorian.year(730739, :value)
  2001

  iex>Elixir.Gregorian.year({2001, 9, 11})
  2001
  iex>Elixir.Gregorian.year({2001, 9, 11}, :atom)
  :year
  iex>Elixir.Gregorian.year({2001, 9, 11}, :index)
  0
  iex>Elixir.Gregorian.year({2001, 9, 11}, :name)
  "Year"
  iex>Elixir.Gregorian.year({2001, 9, 11}, :value)
  2001
Link to this function

year_end(year, type \\ :fixed)

View Source

Specs

year_end(gregorian_year(), :fixed | :date) :: fixed() | gregorian_date()

Returns the last date of the Gregorian year.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Gregorian date.

Examples

  iex>Elixir.Gregorian.year_end(2001)
  731214
  iex>Elixir.Gregorian.year_end(2001, :fixed)
  731214
  iex>Elixir.Gregorian.year_end(2001, :date)
  {2002, 12, 30}