HinduSolar (Calendars v0.2.4) View Source

The HinduSolar calendar module.

Link to this section Summary

Functions

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

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

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

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

Compares two HinduSolar dates and returns...

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

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

Returns the day field of a HinduSolar date.

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

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

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

Returns the number of fields in a HinduSolar date

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

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

Converts a fixed day to a HinduSolar date.

Converts a Julian Day into the equivalent HinduSolar date.

Converts a RataDie date into the equivalent HinduSolar date.

Converts a Unix date into the equivalent HinduSolar date.

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

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

Returns the internal keyword of the HinduSolar calendar.

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

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

Returns the module of the HinduSolar calendar.

Returns the month field of a HinduSolar date.

Returns the internal name of the HinduSolar calendar.

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

Returns the start of the day in the HinduSolar calendar.

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

Converts a HinduSolar date tuple into a fixed day.

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

Converts a HinduSolar date into the equivalent Julian Day.

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

Converts a HinduSolar date into the equivalent RataDie date.

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

Converts a HinduSolar date into the equivalent Unix date.

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

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

Returns the year field of a HinduSolar date.

Link to this section Types

Specs

fixed() :: integer()

Specs

hindu_solar_date() ::
  {hindu_solar_year(), hindu_solar_month(), hindu_solar_day()}

Specs

hindu_solar_day() :: 1..32

Specs

hindu_solar_month() :: 1..12

Specs

hindu_solar_year() :: integer()

Specs

t() :: hindu_solar_date()

Link to this section Functions

Link to this function

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

View Source

Specs

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

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

Examples

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

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

  iex>Elixir.HinduSolar.add_days(730739, 100, :date)
  {1923, 9, 5}
  iex>Elixir.HinduSolar.add_days(730739, -100, :date)
  {1923, 2, 21}

  iex>Elixir.HinduSolar.add_days({1923, 5, 26}, 100)
  730839
  iex>Elixir.HinduSolar.add_days({1923, 5, 26}, -100)
  730639

  iex>Elixir.HinduSolar.add_days({1923, 5, 26}, 100, :fixed)
  730839
  iex>Elixir.HinduSolar.add_days({1923, 5, 26}, -100, :fixed)
  730639

  iex>Elixir.HinduSolar.add_days({1923, 5, 26}, 100, :date)
  {1923, 9, 5}
  iex>Elixir.HinduSolar.add_days({1923, 5, 26}, -100, :date)
  {1923, 2, 21}

Specs

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

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.HinduSolar.as_date(730739)
  {1923, 5, 26}
  iex>Elixir.HinduSolar.as_date({1923, 5, 26})
  {1923, 5, 26}

Specs

as_fixed(fixed() | hindu_solar_date()) :: fixed()

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

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.HinduSolar.as_fixed(730739)
  730739
  iex>Elixir.HinduSolar.as_fixed({1923, 5, 26})
  730739
Link to this function

as_type(cal_date, type \\ :fixed)

View Source

Specs

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

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

The type parameter determines the type of the returned value:

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

Examples

  iex>Elixir.HinduSolar.as_type(730739)
  730739
  iex>Elixir.HinduSolar.as_type(730739, :fixed)
  730739
  iex>Elixir.HinduSolar.as_type(730739, :date)
  {1923, 5, 26}
  iex>Elixir.HinduSolar.as_type({1923, 5, 26})
  730739
  iex>Elixir.HinduSolar.as_type({1923, 5, 26}, :fixed)
  730739
  iex>Elixir.HinduSolar.as_type({1923, 5, 26}, :date)
  {1923, 5, 26}

Specs

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

Compares two HinduSolar 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.HinduSolar.compare({1923, 5, 26}, {1923, 5, 26})
  :eq
  iex>Elixir.HinduSolar.compare({1923, 5, 26}, {1923, 9, 5})
  :lt
  iex>Elixir.HinduSolar.compare({1923, 9, 5}, {1923, 5, 26})
  :gt

Specs

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

Example

  iex>Elixir.HinduSolar.date(1923, 5, 26)
  {1923, 5, 26}
Link to this function

date_diff(cal_date1, cal_date2)

View Source

Specs

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

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

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

day(cal_date, type \\ :value)

View Source

Specs

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

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

  iex>Elixir.HinduSolar.day({1923, 5, 26})
  26
  iex>Elixir.HinduSolar.day({1923, 5, 26}, :atom)
  :day
  iex>Elixir.HinduSolar.day({1923, 5, 26}, :index)
  2
  iex>Elixir.HinduSolar.day({1923, 5, 26}, :name)
  "Day"
  iex>Elixir.HinduSolar.day({1923, 5, 26}, :value)
  26

Specs

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

Examples

  iex>Elixir.HinduSolar.eq({1923, 5, 26}, {1923, 5, 26})
  true
  iex>Elixir.HinduSolar.eq({1923, 5, 26}, {1923, 9, 5})
  false
  iex>Elixir.HinduSolar.eq({1923, 9, 5}, {1923, 5, 26})
  false

Specs

field_atom(integer()) :: atom()

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

Examples

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

Specs

field_atoms() :: [atom()]

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

Example

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

Specs

field_count() :: integer()

Returns the number of fields in a HinduSolar date

Example

  iex>Elixir.HinduSolar.field_count()
  3

Specs

field_index(atom()) :: integer()

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

Examples

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

from_date(other_date, other_calendar)

View Source

Specs

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

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

Example

  iex>Elixir.HinduSolar.from_date({2001, 9, 11}, Gregorian)
  {1923, 5, 26}

Specs

from_fixed(fixed()) :: hindu_solar_date()

Converts a fixed day to a HinduSolar date.

Example

  iex>Elixir.HinduSolar.from_fixed(730739)
  {1923, 5, 26}

Specs

from_jd(tuple() | number()) :: hindu_solar_date()

Converts a Julian Day into the equivalent HinduSolar date.

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

Examples

  iex>Elixir.HinduSolar.from_jd({2452163.5})
  {1923, 5, 26}
  iex>Elixir.HinduSolar.from_jd(2452163.5)
  {1923, 5, 26}

Specs

from_rata_die(tuple() | integer()) :: hindu_solar_date()

Converts a RataDie date into the equivalent HinduSolar date.

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

Examples

  iex>Elixir.HinduSolar.from_rata_die({730739})
  {1923, 5, 26}
  iex>Elixir.HinduSolar.from_rata_die(730739)
  {1923, 5, 26}

Specs

from_unix(tuple() | integer()) :: hindu_solar_date()

Converts a Unix date into the equivalent HinduSolar date.

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

Examples

  iex>Elixir.HinduSolar.from_unix({1000166400})
  {1923, 5, 26}
  iex>Elixir.HinduSolar.from_unix(1000166400)
  {1923, 5, 26}

Specs

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

Examples

  iex>Elixir.HinduSolar.ge({1923, 5, 26}, {1923, 5, 26})
  true
  iex>Elixir.HinduSolar.ge({1923, 5, 26}, {1923, 9, 5})
  false
  iex>Elixir.HinduSolar.ge({1923, 9, 5}, {1923, 5, 26})
  true

Specs

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

Examples

  iex>Elixir.HinduSolar.gt({1923, 5, 26}, {1923, 5, 26})
  false
  iex>Elixir.HinduSolar.gt({1923, 5, 26}, {1923, 9, 5})
  false
  iex>Elixir.HinduSolar.gt({1923, 9, 5}, {1923, 5, 26})
  true

Specs

keyword() :: atom()

Returns the internal keyword of the HinduSolar calendar.

Example

  iex>Elixir.HinduSolar.keyword()
  :hindu_solar

Specs

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

Examples

  iex>Elixir.HinduSolar.le({1923, 5, 26}, {1923, 5, 26})
  true
  iex>Elixir.HinduSolar.le({1923, 5, 26}, {1923, 9, 5})
  true
  iex>Elixir.HinduSolar.le({1923, 9, 5}, {1923, 5, 26})
  false

Specs

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

Examples

  iex>Elixir.HinduSolar.lt({1923, 5, 26}, {1923, 5, 26})
  false
  iex>Elixir.HinduSolar.lt({1923, 5, 26}, {1923, 9, 5})
  true
  iex>Elixir.HinduSolar.lt({1923, 9, 5}, {1923, 5, 26})
  false

Specs

module() :: module()

Returns the module of the HinduSolar calendar.

Example

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

month(cal_date, type \\ :value)

View Source

Specs

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

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

  iex>Elixir.HinduSolar.month({1923, 5, 26})
  5
  iex>Elixir.HinduSolar.month({1923, 5, 26}, :atom)
  :month
  iex>Elixir.HinduSolar.month({1923, 5, 26}, :index)
  1
  iex>Elixir.HinduSolar.month({1923, 5, 26}, :name)
  "Month"
  iex>Elixir.HinduSolar.month({1923, 5, 26}, :value)
  5

Specs

name() :: atom()

Returns the internal name of the HinduSolar calendar.

Example

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

Specs

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

Example

  iex>Elixir.HinduSolar.range({1923, 5, 26}, {1923, 9, 5})
  730739..730839

Specs

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

Returns the start of the day in the HinduSolar calendar.

Possible return values are:

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

Example

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

to_date(date, other_calendar)

View Source

Specs

to_date(hindu_solar_date(), module()) :: tuple()

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

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

Example

  iex>Elixir.HinduSolar.to_date({1923, 5, 26}, Gregorian)
  {2001, 9, 11}

Specs

to_fixed(hindu_solar_date()) :: fixed()

Converts a HinduSolar date tuple into a fixed day.

Example

  iex>Elixir.HinduSolar.to_fixed({1923, 5, 26})
  730739
Link to this function

to_fixed(year, month, day)

View Source

Specs

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

Example

  iex>Elixir.HinduSolar.to_fixed(1923, 5, 26)
  730739

Specs

to_jd(hindu_solar_date()) :: {number()}

Converts a HinduSolar date into the equivalent Julian Day.

Example

  iex>Elixir.HinduSolar.to_jd({1923, 5, 26})
  {2452163.5}

Specs

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

Example

  iex>Elixir.HinduSolar.to_jd(1923, 5, 26)
  {2452163.5}

Specs

to_rata_die(hindu_solar_date()) :: {integer()}

Converts a HinduSolar date into the equivalent RataDie date.

Example

  iex>Elixir.HinduSolar.to_rata_die({1923, 5, 26})
  {730739}
Link to this function

to_rata_die(year, month, day)

View Source

Specs

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

Example

  iex>Elixir.HinduSolar.to_rata_die(1923, 5, 26)
  {730739}

Specs

to_unix(hindu_solar_date()) :: {integer()}

Converts a HinduSolar date into the equivalent Unix date.

Example

  iex>Elixir.HinduSolar.to_unix({1923, 5, 26})
  {1000166400}
Link to this function

to_unix(year, month, day)

View Source

Specs

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

Example

  iex>Elixir.HinduSolar.to_unix(1923, 5, 26)
  {1000166400}

Specs

today(:fixed | :date) :: fixed() | hindu_solar_date()

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

Examples

  Elixir.HinduSolar.today()
  730739
  Elixir.HinduSolar.today(:fixed)
  730739
  Elixir.HinduSolar.today(:date)
  {1923, 5, 26}
Link to this function

year(cal_date, type \\ :value)

View Source

Specs

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

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

  iex>Elixir.HinduSolar.year({1923, 5, 26})
  1923
  iex>Elixir.HinduSolar.year({1923, 5, 26}, :atom)
  :year
  iex>Elixir.HinduSolar.year({1923, 5, 26}, :index)
  0
  iex>Elixir.HinduSolar.year({1923, 5, 26}, :name)
  "Year"
  iex>Elixir.HinduSolar.year({1923, 5, 26}, :value)
  1923