Bahai (Calendars v0.2.4) View Source

The Bahai calendar module.

Link to this section Summary

Functions

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

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

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

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

Returns the fixed date of Baha'i New Year of the Bahai calendar in the given gregorian_year or [], if there is no such holiday in that year.

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

Compares two Bahai dates and returns...

Returns the cycle field of a Bahai date.

Returns a Bahai date from its fields major, cycle, year, month, day.

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

Returns the day field of a Bahai date.

Returns the epoch of the Bahai calendar.

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

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

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

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

Returns the number of fields in a Bahai date

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

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

Converts a fixed day to a Bahai date.

Converts a Julian Day into the equivalent Bahai date.

Converts a RataDie date into the equivalent Bahai date.

Converts a Unix date into the equivalent Bahai date.

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

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

Returns a list of the holidays of the Bahai calendar.

Returns the internal keyword of the Bahai calendar.

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

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

Returns the major field of a Bahai date.

Returns the module of the Bahai calendar.

Returns the month field of a Bahai date.

Returns the internal name of the Bahai calendar.

Returns the fixed date of Feast of Naw-Ruz of the Bahai calendar in the given gregorian_year or [], if there is no such holiday in that year.

Returns the first date of the Bahai year.

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

Returns the start of the day in the Bahai calendar.

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

Converts a Bahai date tuple into a fixed day.

Converts a Bahai date given by major, cycle, year, month, day into a fixed day.

Converts a Bahai date into the equivalent Julian Day.

Converts a Bahai date given by major, cycle, year, month, day into the equivalent Julian Day.

Converts a Bahai date into the equivalent RataDie date.

Converts a Bahai date given by major, cycle, year, month, day into the equivalent RataDie date.

Converts a Bahai date into the equivalent Unix date.

Converts a Bahai date given by major, cycle, year, month, day into the equivalent Unix date.

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

Returns the year field of a Bahai date.

Link to this section Types

Specs

bahai_cycle() :: 1..19

Specs

bahai_date() ::
  {bahai_major(), bahai_cycle(), bahai_year(), bahai_month(), bahai_day()}

Specs

bahai_day() :: 1..19

Specs

bahai_major() :: integer()

Specs

bahai_month() :: 0..19

Specs

bahai_year() :: 1..19

Specs

fixed() :: integer()

Specs

t() :: bahai_date()

Link to this section Functions

Link to this function

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

View Source

Specs

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

Adds the number of days to a fixed day or Bahai 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 Bahai date.

Examples

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

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

  iex>Elixir.Bahai.add_days(730739, 100, :date)
  {1, 9, 6, 15, 9}
  iex>Elixir.Bahai.add_days(730739, -100, :date)
  {1, 9, 6, 4, 18}

  iex>Elixir.Bahai.add_days({1, 9, 6, 10, 4}, 100)
  730839
  iex>Elixir.Bahai.add_days({1, 9, 6, 10, 4}, -100)
  730639

  iex>Elixir.Bahai.add_days({1, 9, 6, 10, 4}, 100, :fixed)
  730839
  iex>Elixir.Bahai.add_days({1, 9, 6, 10, 4}, -100, :fixed)
  730639

  iex>Elixir.Bahai.add_days({1, 9, 6, 10, 4}, 100, :date)
  {1, 9, 6, 15, 9}
  iex>Elixir.Bahai.add_days({1, 9, 6, 10, 4}, -100, :date)
  {1, 9, 6, 4, 18}

Specs

as_date(fixed() | bahai_date()) :: bahai_date()

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

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.Bahai.as_date(730739)
  {1, 9, 6, 10, 4}
  iex>Elixir.Bahai.as_date({1, 9, 6, 10, 4})
  {1, 9, 6, 10, 4}

Specs

as_fixed(fixed() | bahai_date()) :: fixed()

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

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.Bahai.as_fixed(730739)
  730739
  iex>Elixir.Bahai.as_fixed({1, 9, 6, 10, 4})
  730739
Link to this function

as_type(cal_date, type \\ :fixed)

View Source

Specs

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

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

The type parameter determines the type of the returned value:

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

Examples

  iex>Elixir.Bahai.as_type(730739)
  730739
  iex>Elixir.Bahai.as_type(730739, :fixed)
  730739
  iex>Elixir.Bahai.as_type(730739, :date)
  {1, 9, 6, 10, 4}
  iex>Elixir.Bahai.as_type({1, 9, 6, 10, 4})
  730739
  iex>Elixir.Bahai.as_type({1, 9, 6, 10, 4}, :fixed)
  730739
  iex>Elixir.Bahai.as_type({1, 9, 6, 10, 4}, :date)
  {1, 9, 6, 10, 4}
Link to this function

bahai_new_year(gregorian_year)

View Source

Specs

bahai_new_year(Gregorian.gregorian_year()) :: fixed() | bahai_date()

Returns the fixed date of Baha'i New Year of the Bahai 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 Bahai date.

Example

  iex>Elixir.Bahai.bahai_new_year(2001)
  {2001, 3, 21}
Link to this function

birth_of_the_bab(gregorian_year)

View Source

Specs

birth_of_the_bab(Gregorian.gregorian_year()) :: fixed() | bahai_date()

Returns the fixed date of Birth of the Bab of the Bahai 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 Bahai date.

Example

  iex>Elixir.Bahai.birth_of_the_bab(2001)
  {2001, 10, 18}

Specs

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

Compares two Bahai 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.Bahai.compare({1, 9, 6, 10, 4}, {1, 9, 6, 10, 4})
  :eq
  iex>Elixir.Bahai.compare({1, 9, 6, 10, 4}, {1, 9, 6, 15, 9})
  :lt
  iex>Elixir.Bahai.compare({1, 9, 6, 15, 9}, {1, 9, 6, 10, 4})
  :gt
Link to this function

cycle(cal_date, type \\ :value)

View Source

Specs

cycle(fixed() | bahai_date(), :atom | :index | :name | :value) ::
  :atom | integer() | String.t() | number()

Returns the cycle field of a Bahai date.

The type parameter determines the type of the returned cycle:

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

Examples

  iex>Elixir.Bahai.cycle(730739)
  9
  iex>Elixir.Bahai.cycle(730739, :atom)
  :cycle
  iex>Elixir.Bahai.cycle(730739, :index)
  1
  iex>Elixir.Bahai.cycle(730739, :name)
  "Cycle"
  iex>Elixir.Bahai.cycle(730739, :value)
  9

  iex>Elixir.Bahai.cycle({1, 9, 6, 10, 4})
  9
  iex>Elixir.Bahai.cycle({1, 9, 6, 10, 4}, :atom)
  :cycle
  iex>Elixir.Bahai.cycle({1, 9, 6, 10, 4}, :index)
  1
  iex>Elixir.Bahai.cycle({1, 9, 6, 10, 4}, :name)
  "Cycle"
  iex>Elixir.Bahai.cycle({1, 9, 6, 10, 4}, :value)
  9
Link to this function

date(major, cycle, year, month, day)

View Source

Specs

Returns a Bahai date from its fields major, cycle, year, month, day.

Example

  iex>Elixir.Bahai.date(1, 9, 6, 10, 4)
  {1, 9, 6, 10, 4}
Link to this function

date_diff(cal_date1, cal_date2)

View Source

Specs

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

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

The dates can be given as fixed days or Bahai 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.Bahai.date_diff(730739, 730839)
  100
  iex>Elixir.Bahai.date_diff(730839, 730739)
  -100
  iex>Elixir.Bahai.date_diff({1, 9, 6, 10, 4}, {1, 9, 6, 15, 9})
  100
  iex>Elixir.Bahai.date_diff({1, 9, 6, 15, 9}, {1, 9, 6, 10, 4})
  -100
  iex>Elixir.Bahai.date_diff(730739, {1, 9, 6, 15, 9})
  100
  iex>Elixir.Bahai.date_diff({1, 9, 6, 10, 4}, 730839)
  100
Link to this function

day(cal_date, type \\ :value)

View Source

Specs

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

Returns the day field of a Bahai 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.Bahai.day(730739)
  4
  iex>Elixir.Bahai.day(730739, :atom)
  :day
  iex>Elixir.Bahai.day(730739, :index)
  4
  iex>Elixir.Bahai.day(730739, :name)
  "Day"
  iex>Elixir.Bahai.day(730739, :value)
  4

  iex>Elixir.Bahai.day({1, 9, 6, 10, 4})
  4
  iex>Elixir.Bahai.day({1, 9, 6, 10, 4}, :atom)
  :day
  iex>Elixir.Bahai.day({1, 9, 6, 10, 4}, :index)
  4
  iex>Elixir.Bahai.day({1, 9, 6, 10, 4}, :name)
  "Day"
  iex>Elixir.Bahai.day({1, 9, 6, 10, 4}, :value)
  4

Specs

epoch() :: number()

Returns the epoch of the Bahai calendar.

Example

  iex>Elixir.Bahai.epoch()
  673222

Specs

eq(bahai_date(), bahai_date()) :: boolean()

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

Examples

  iex>Elixir.Bahai.eq({1, 9, 6, 10, 4}, {1, 9, 6, 10, 4})
  true
  iex>Elixir.Bahai.eq({1, 9, 6, 10, 4}, {1, 9, 6, 15, 9})
  false
  iex>Elixir.Bahai.eq({1, 9, 6, 15, 9}, {1, 9, 6, 10, 4})
  false
Link to this function

feast_of_ridvan(gregorian_year)

View Source

Specs

feast_of_ridvan(Gregorian.gregorian_year()) :: fixed() | bahai_date()

Returns the fixed date of Feast of Ridvan of the Bahai 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 Bahai date.

Example

  iex>Elixir.Bahai.feast_of_ridvan(2001)
  {2001, 4, 20}

Specs

field_atom(integer()) :: atom()

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

Examples

  iex>Elixir.Bahai.field_atom(0)
  :major
  iex>Elixir.Bahai.field_atom(1)
  :cycle
  iex>Elixir.Bahai.field_atom(2)
  :year
  iex>Elixir.Bahai.field_atom(3)
  :month
  iex>Elixir.Bahai.field_atom(4)
  :day

Specs

field_atoms() :: [atom()]

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

Example

  iex>Elixir.Bahai.field_atoms()
  [:major, :cycle, :year, :month, :day]

Specs

field_count() :: integer()

Returns the number of fields in a Bahai date

Example

  iex>Elixir.Bahai.field_count()
  5

Specs

field_index(atom()) :: integer()

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

Examples

  iex>Elixir.Bahai.field_index(:major)
  0
  iex>Elixir.Bahai.field_index(:cycle)
  1
  iex>Elixir.Bahai.field_index(:year)
  2
  iex>Elixir.Bahai.field_index(:month)
  3
  iex>Elixir.Bahai.field_index(:day)
  4
Link to this function

from_date(other_date, other_calendar)

View Source

Specs

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

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

Example

  iex>Elixir.Bahai.from_date({2001, 9, 11}, Gregorian)
  {1, 9, 6, 10, 4}

Specs

from_fixed(fixed()) :: bahai_date()

Converts a fixed day to a Bahai date.

Example

  iex>Elixir.Bahai.from_fixed(730739)
  {1, 9, 6, 10, 4}

Specs

from_jd(tuple() | number()) :: bahai_date()

Converts a Julian Day into the equivalent Bahai date.

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

Examples

  iex>Elixir.Bahai.from_jd({2452163.5})
  {1, 9, 6, 10, 4}
  iex>Elixir.Bahai.from_jd(2452163.5)
  {1, 9, 6, 10, 4}

Specs

from_rata_die(tuple() | integer()) :: bahai_date()

Converts a RataDie date into the equivalent Bahai date.

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

Examples

  iex>Elixir.Bahai.from_rata_die({730739})
  {1, 9, 6, 10, 4}
  iex>Elixir.Bahai.from_rata_die(730739)
  {1, 9, 6, 10, 4}

Specs

from_unix(tuple() | integer()) :: bahai_date()

Converts a Unix date into the equivalent Bahai date.

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

Examples

  iex>Elixir.Bahai.from_unix({1000166400})
  {1, 9, 6, 10, 4}
  iex>Elixir.Bahai.from_unix(1000166400)
  {1, 9, 6, 10, 4}

Specs

ge(bahai_date(), bahai_date()) :: boolean()

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

Examples

  iex>Elixir.Bahai.ge({1, 9, 6, 10, 4}, {1, 9, 6, 10, 4})
  true
  iex>Elixir.Bahai.ge({1, 9, 6, 10, 4}, {1, 9, 6, 15, 9})
  false
  iex>Elixir.Bahai.ge({1, 9, 6, 15, 9}, {1, 9, 6, 10, 4})
  true

Specs

gt(bahai_date(), bahai_date()) :: boolean()

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

Examples

  iex>Elixir.Bahai.gt({1, 9, 6, 10, 4}, {1, 9, 6, 10, 4})
  false
  iex>Elixir.Bahai.gt({1, 9, 6, 10, 4}, {1, 9, 6, 15, 9})
  false
  iex>Elixir.Bahai.gt({1, 9, 6, 15, 9}, {1, 9, 6, 10, 4})
  true

Returns a list of the holidays of the Bahai 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.Bahai.holidays()
  ["Baha'i New Year", "Birth of the Bab", "Feast of Naw-Ruz", "Feast of Ridvan"]
  iex>Elixir.Bahai.holidays(:atom)
  [:bahai_new_year, :birth_of_the_bab, :naw_ruz, :feast_of_ridvan]
  iex>Elixir.Bahai.holidays(:name)
  ["Baha'i New Year", "Birth of the Bab", "Feast of Naw-Ruz", "Feast of Ridvan"]

Specs

keyword() :: atom()

Returns the internal keyword of the Bahai calendar.

Example

  iex>Elixir.Bahai.keyword()
  :bahai

Specs

le(bahai_date(), bahai_date()) :: boolean()

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

Examples

  iex>Elixir.Bahai.le({1, 9, 6, 10, 4}, {1, 9, 6, 10, 4})
  true
  iex>Elixir.Bahai.le({1, 9, 6, 10, 4}, {1, 9, 6, 15, 9})
  true
  iex>Elixir.Bahai.le({1, 9, 6, 15, 9}, {1, 9, 6, 10, 4})
  false

Specs

lt(bahai_date(), bahai_date()) :: boolean()

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

Examples

  iex>Elixir.Bahai.lt({1, 9, 6, 10, 4}, {1, 9, 6, 10, 4})
  false
  iex>Elixir.Bahai.lt({1, 9, 6, 10, 4}, {1, 9, 6, 15, 9})
  true
  iex>Elixir.Bahai.lt({1, 9, 6, 15, 9}, {1, 9, 6, 10, 4})
  false
Link to this function

major(cal_date, type \\ :value)

View Source

Specs

major(fixed() | bahai_date(), :atom | :index | :name | :value) ::
  :atom | integer() | String.t() | number()

Returns the major field of a Bahai date.

The type parameter determines the type of the returned major:

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

Examples

  iex>Elixir.Bahai.major(730739)
  1
  iex>Elixir.Bahai.major(730739, :atom)
  :major
  iex>Elixir.Bahai.major(730739, :index)
  0
  iex>Elixir.Bahai.major(730739, :name)
  "Major"
  iex>Elixir.Bahai.major(730739, :value)
  1

  iex>Elixir.Bahai.major({1, 9, 6, 10, 4})
  1
  iex>Elixir.Bahai.major({1, 9, 6, 10, 4}, :atom)
  :major
  iex>Elixir.Bahai.major({1, 9, 6, 10, 4}, :index)
  0
  iex>Elixir.Bahai.major({1, 9, 6, 10, 4}, :name)
  "Major"
  iex>Elixir.Bahai.major({1, 9, 6, 10, 4}, :value)
  1

Specs

module() :: module()

Returns the module of the Bahai calendar.

Example

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

month(cal_date, type \\ :value)

View Source

Specs

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

Returns the month field of a Bahai 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.Bahai.month(730739)
  10
  iex>Elixir.Bahai.month(730739, :atom)
  :month
  iex>Elixir.Bahai.month(730739, :index)
  3
  iex>Elixir.Bahai.month(730739, :name)
  "Month"
  iex>Elixir.Bahai.month(730739, :value)
  10

  iex>Elixir.Bahai.month({1, 9, 6, 10, 4})
  10
  iex>Elixir.Bahai.month({1, 9, 6, 10, 4}, :atom)
  :month
  iex>Elixir.Bahai.month({1, 9, 6, 10, 4}, :index)
  3
  iex>Elixir.Bahai.month({1, 9, 6, 10, 4}, :name)
  "Month"
  iex>Elixir.Bahai.month({1, 9, 6, 10, 4}, :value)
  10

Specs

name() :: atom()

Returns the internal name of the Bahai calendar.

Example

  iex>Elixir.Bahai.name()
  "Bahai"

Specs

Returns the fixed date of Feast of Naw-Ruz of the Bahai 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 Bahai date.

Example

  iex>Elixir.Bahai.naw_ruz(2001)
  {2001, 3, 20}
Link to this function

new_year(year, type \\ :fixed)

View Source

Specs

new_year(bahai_year(), :fixed | :date) :: fixed() | bahai_date()

Returns the first date of the Bahai year.

The type parameter determines the type of the returned value:

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

Examples

  iex>Elixir.Bahai.new_year(6)
  1906
  iex>Elixir.Bahai.new_year(6, :fixed)
  1906
  iex>Elixir.Bahai.new_year(6, :date)
  {-5, 18, 6, 1, 1}

Specs

range(bahai_date(), bahai_date()) :: integer()

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

Example

  iex>Elixir.Bahai.range({1, 9, 6, 10, 4}, {1, 9, 6, 15, 9})
  730739..730839

Specs

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

Returns the start of the day in the Bahai calendar.

Possible return values are:

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

Example

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

to_date(date, other_calendar)

View Source

Specs

to_date(bahai_date(), module()) :: tuple()

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

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

Example

  iex>Elixir.Bahai.to_date({1, 9, 6, 10, 4}, Gregorian)
  {2001, 9, 11}

Specs

to_fixed(bahai_date()) :: fixed()

Converts a Bahai date tuple into a fixed day.

Example

  iex>Elixir.Bahai.to_fixed({1, 9, 6, 10, 4})
  730739
Link to this function

to_fixed(major, cycle, year, month, day)

View Source

Specs

Converts a Bahai date given by major, cycle, year, month, day into a fixed day.

Example

  iex>Elixir.Bahai.to_fixed(1, 9, 6, 10, 4)
  730739

Specs

to_jd(bahai_date()) :: {number()}

Converts a Bahai date into the equivalent Julian Day.

Example

  iex>Elixir.Bahai.to_jd({1, 9, 6, 10, 4})
  {2452163.5}
Link to this function

to_jd(major, cycle, year, month, day)

View Source

Specs

Converts a Bahai date given by major, cycle, year, month, day into the equivalent Julian Day.

Example

  iex>Elixir.Bahai.to_jd(1, 9, 6, 10, 4)
  {2452163.5}

Specs

to_rata_die(bahai_date()) :: {integer()}

Converts a Bahai date into the equivalent RataDie date.

Example

  iex>Elixir.Bahai.to_rata_die({1, 9, 6, 10, 4})
  {730739}
Link to this function

to_rata_die(major, cycle, year, month, day)

View Source

Specs

to_rata_die(
  bahai_major(),
  bahai_cycle(),
  bahai_year(),
  bahai_month(),
  bahai_day()
) :: {integer()}

Converts a Bahai date given by major, cycle, year, month, day into the equivalent RataDie date.

Example

  iex>Elixir.Bahai.to_rata_die(1, 9, 6, 10, 4)
  {730739}

Specs

to_unix(bahai_date()) :: {integer()}

Converts a Bahai date into the equivalent Unix date.

Example

  iex>Elixir.Bahai.to_unix({1, 9, 6, 10, 4})
  {1000166400}
Link to this function

to_unix(major, cycle, year, month, day)

View Source

Specs

Converts a Bahai date given by major, cycle, year, month, day into the equivalent Unix date.

Example

  iex>Elixir.Bahai.to_unix(1, 9, 6, 10, 4)
  {1000166400}

Specs

today(:fixed | :date) :: fixed() | bahai_date()

Returns the current date either as a fixed day or a Bahai 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 Bahai date.

Examples

  Elixir.Bahai.today()
  730739
  Elixir.Bahai.today(:fixed)
  730739
  Elixir.Bahai.today(:date)
  {1, 9, 6, 10, 4}
Link to this function

year(cal_date, type \\ :value)

View Source

Specs

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

Returns the year field of a Bahai 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.Bahai.year(730739)
  6
  iex>Elixir.Bahai.year(730739, :atom)
  :year
  iex>Elixir.Bahai.year(730739, :index)
  2
  iex>Elixir.Bahai.year(730739, :name)
  "Year"
  iex>Elixir.Bahai.year(730739, :value)
  6

  iex>Elixir.Bahai.year({1, 9, 6, 10, 4})
  6
  iex>Elixir.Bahai.year({1, 9, 6, 10, 4}, :atom)
  :year
  iex>Elixir.Bahai.year({1, 9, 6, 10, 4}, :index)
  2
  iex>Elixir.Bahai.year({1, 9, 6, 10, 4}, :name)
  "Year"
  iex>Elixir.Bahai.year({1, 9, 6, 10, 4}, :value)
  6