AstroBahai (Calendars v0.2.4) View Source

The AstroBahai calendar module.

Link to this section Summary

Functions

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

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

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

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

Compares two AstroBahai dates and returns...

Returns the cycle field of a AstroBahai date.

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

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

Returns the day field of a AstroBahai date.

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

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

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

Returns the number of fields in a AstroBahai date

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

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

Converts a fixed day to a AstroBahai date.

Converts a Julian Day into the equivalent AstroBahai date.

Converts a RataDie date into the equivalent AstroBahai date.

Converts a Unix date into the equivalent AstroBahai date.

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

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

Returns the internal keyword of the AstroBahai calendar.

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

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

Returns the major field of a AstroBahai date.

Returns the module of the AstroBahai calendar.

Returns the month field of a AstroBahai date.

Returns the internal name of the AstroBahai calendar.

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

Returns the start of the day in the AstroBahai calendar.

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

Converts a AstroBahai date tuple into a fixed day.

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

Converts a AstroBahai date into the equivalent Julian Day.

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

Converts a AstroBahai date into the equivalent RataDie date.

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

Converts a AstroBahai date into the equivalent Unix date.

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

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

Returns the year field of a AstroBahai date.

Link to this section Types

Specs

astro_bahai_cycle() :: 1..19

Specs

Specs

astro_bahai_day() :: 1..19

Specs

astro_bahai_major() :: integer()

Specs

astro_bahai_month() :: 0..19

Specs

astro_bahai_year() :: 1..19

Specs

fixed() :: integer()

Specs

t() :: astro_bahai_date()

Link to this section Functions

Link to this function

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

View Source

Specs

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

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

Examples

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

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

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

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

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

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

Specs

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

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.AstroBahai.as_date(730739)
  {1, 9, 6, 10, 5}
  iex>Elixir.AstroBahai.as_date({1, 9, 6, 10, 5})
  {1, 9, 6, 10, 5}

Specs

as_fixed(fixed() | astro_bahai_date()) :: fixed()

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

This is a convenience function to simplify certain function calls.

Examples

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

as_type(cal_date, type \\ :fixed)

View Source

Specs

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

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

The type parameter determines the type of the returned value:

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

Examples

  iex>Elixir.AstroBahai.as_type(730739)
  730739
  iex>Elixir.AstroBahai.as_type(730739, :fixed)
  730739
  iex>Elixir.AstroBahai.as_type(730739, :date)
  {1, 9, 6, 10, 5}
  iex>Elixir.AstroBahai.as_type({1, 9, 6, 10, 5})
  730739
  iex>Elixir.AstroBahai.as_type({1, 9, 6, 10, 5}, :fixed)
  730739
  iex>Elixir.AstroBahai.as_type({1, 9, 6, 10, 5}, :date)
  {1, 9, 6, 10, 5}

Specs

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

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

cycle(cal_date, type \\ :value)

View Source

Specs

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

Returns the cycle field of a AstroBahai 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.AstroBahai.cycle(730739)
  9
  iex>Elixir.AstroBahai.cycle(730739, :atom)
  :cycle
  iex>Elixir.AstroBahai.cycle(730739, :index)
  1
  iex>Elixir.AstroBahai.cycle(730739, :name)
  "Cycle"
  iex>Elixir.AstroBahai.cycle(730739, :value)
  9

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

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

View Source

Specs

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

Example

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

date_diff(cal_date1, cal_date2)

View Source

Specs

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

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

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

day(cal_date, type \\ :value)

View Source

Specs

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

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

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

Specs

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

Examples

  iex>Elixir.AstroBahai.eq({1, 9, 6, 10, 5}, {1, 9, 6, 10, 5})
  true
  iex>Elixir.AstroBahai.eq({1, 9, 6, 10, 5}, {1, 9, 6, 15, 10})
  false
  iex>Elixir.AstroBahai.eq({1, 9, 6, 15, 10}, {1, 9, 6, 10, 5})
  false

Specs

field_atom(integer()) :: atom()

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

Examples

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

Specs

field_atoms() :: [atom()]

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

Example

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

Specs

field_count() :: integer()

Returns the number of fields in a AstroBahai date

Example

  iex>Elixir.AstroBahai.field_count()
  5

Specs

field_index(atom()) :: integer()

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

Examples

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

from_date(other_date, other_calendar)

View Source

Specs

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

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

Example

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

Specs

from_fixed(fixed()) :: astro_bahai_date()

Converts a fixed day to a AstroBahai date.

Example

  iex>Elixir.AstroBahai.from_fixed(730739)
  {1, 9, 6, 10, 5}

Specs

from_jd(tuple() | number()) :: astro_bahai_date()

Converts a Julian Day into the equivalent AstroBahai date.

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

Examples

  iex>Elixir.AstroBahai.from_jd({2452163.5})
  {1, 9, 6, 10, 5}
  iex>Elixir.AstroBahai.from_jd(2452163.5)
  {1, 9, 6, 10, 5}

Specs

from_rata_die(tuple() | integer()) :: astro_bahai_date()

Converts a RataDie date into the equivalent AstroBahai date.

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

Examples

  iex>Elixir.AstroBahai.from_rata_die({730739})
  {1, 9, 6, 10, 5}
  iex>Elixir.AstroBahai.from_rata_die(730739)
  {1, 9, 6, 10, 5}

Specs

from_unix(tuple() | integer()) :: astro_bahai_date()

Converts a Unix date into the equivalent AstroBahai date.

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

Examples

  iex>Elixir.AstroBahai.from_unix({1000166400})
  {1, 9, 6, 10, 5}
  iex>Elixir.AstroBahai.from_unix(1000166400)
  {1, 9, 6, 10, 5}

Specs

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

Examples

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

Specs

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

Examples

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

Specs

keyword() :: atom()

Returns the internal keyword of the AstroBahai calendar.

Example

  iex>Elixir.AstroBahai.keyword()
  :astro_bahai

Specs

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

Examples

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

Specs

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

Examples

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

major(cal_date, type \\ :value)

View Source

Specs

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

Returns the major field of a AstroBahai 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.AstroBahai.major(730739)
  1
  iex>Elixir.AstroBahai.major(730739, :atom)
  :major
  iex>Elixir.AstroBahai.major(730739, :index)
  0
  iex>Elixir.AstroBahai.major(730739, :name)
  "Major"
  iex>Elixir.AstroBahai.major(730739, :value)
  1

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

Specs

module() :: module()

Returns the module of the AstroBahai calendar.

Example

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

month(cal_date, type \\ :value)

View Source

Specs

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

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

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

Specs

name() :: atom()

Returns the internal name of the AstroBahai calendar.

Example

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

Specs

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

Example

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

Specs

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

Returns the start of the day in the AstroBahai calendar.

Possible return values are:

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

Example

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

to_date(date, other_calendar)

View Source

Specs

to_date(astro_bahai_date(), module()) :: tuple()

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

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

Example

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

Specs

to_fixed(astro_bahai_date()) :: fixed()

Converts a AstroBahai date tuple into a fixed day.

Example

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

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

View Source

Specs

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

Example

  iex>Elixir.AstroBahai.to_fixed(1, 9, 6, 10, 5)
  730739

Specs

to_jd(astro_bahai_date()) :: {number()}

Converts a AstroBahai date into the equivalent Julian Day.

Example

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

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

View Source

Specs

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

Example

  iex>Elixir.AstroBahai.to_jd(1, 9, 6, 10, 5)
  {2452163.5}

Specs

to_rata_die(astro_bahai_date()) :: {integer()}

Converts a AstroBahai date into the equivalent RataDie date.

Example

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

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

View Source

Specs

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

Example

  iex>Elixir.AstroBahai.to_rata_die(1, 9, 6, 10, 5)
  {730739}

Specs

to_unix(astro_bahai_date()) :: {integer()}

Converts a AstroBahai date into the equivalent Unix date.

Example

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

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

View Source

Specs

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

Example

  iex>Elixir.AstroBahai.to_unix(1, 9, 6, 10, 5)
  {1000166400}

Specs

today(:fixed | :date) :: fixed() | astro_bahai_date()

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

Examples

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

year(cal_date, type \\ :value)

View Source

Specs

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

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

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