SaudiIslamic (Calendars v0.2.4) View Source

The SaudiIslamic calendar module.

Link to this section Summary

Functions

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

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

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

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

Compares two SaudiIslamic dates and returns...

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

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

Returns the day field of a SaudiIslamic date.

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

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

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

Returns the number of fields in a SaudiIslamic date

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

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

Converts a fixed day to a SaudiIslamic date.

Converts a Julian Day into the equivalent SaudiIslamic date.

Converts a RataDie date into the equivalent SaudiIslamic date.

Converts a Unix date into the equivalent SaudiIslamic date.

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

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

Returns the internal keyword of the SaudiIslamic calendar.

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

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

Returns the module of the SaudiIslamic calendar.

Returns the month field of a SaudiIslamic date.

Returns the internal name of the SaudiIslamic calendar.

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

Returns the start of the day in the SaudiIslamic calendar.

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

Converts a SaudiIslamic date tuple into a fixed day.

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

Converts a SaudiIslamic date into the equivalent Julian Day.

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

Converts a SaudiIslamic date into the equivalent RataDie date.

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

Converts a SaudiIslamic date into the equivalent Unix date.

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

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

Returns the year field of a SaudiIslamic date.

Link to this section Types

Specs

fixed() :: integer()

Specs

saudi_islamic_date() ::
  {saudi_islamic_year(), saudi_islamic_month(), saudi_islamic_day()}

Specs

saudi_islamic_day() :: 1..30

Specs

saudi_islamic_month() :: 1..12

Specs

saudi_islamic_year() :: :integer

Specs

Link to this section Functions

Link to this function

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

View Source

Specs

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

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

Examples

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

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

  iex>Elixir.SaudiIslamic.add_days(730739, 100, :date)
  {1422, 10, 5}
  iex>Elixir.SaudiIslamic.add_days(730739, -100, :date)
  {1422, 3, 11}

  iex>Elixir.SaudiIslamic.add_days({1422, 6, 23}, 100)
  730839
  iex>Elixir.SaudiIslamic.add_days({1422, 6, 23}, -100)
  730639

  iex>Elixir.SaudiIslamic.add_days({1422, 6, 23}, 100, :fixed)
  730839
  iex>Elixir.SaudiIslamic.add_days({1422, 6, 23}, -100, :fixed)
  730639

  iex>Elixir.SaudiIslamic.add_days({1422, 6, 23}, 100, :date)
  {1422, 10, 5}
  iex>Elixir.SaudiIslamic.add_days({1422, 6, 23}, -100, :date)
  {1422, 3, 11}

Specs

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

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.SaudiIslamic.as_date(730739)
  {1422, 6, 23}
  iex>Elixir.SaudiIslamic.as_date({1422, 6, 23})
  {1422, 6, 23}

Specs

as_fixed(fixed() | saudi_islamic_date()) :: fixed()

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

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.SaudiIslamic.as_fixed(730739)
  730739
  iex>Elixir.SaudiIslamic.as_fixed({1422, 6, 23})
  730739
Link to this function

as_type(cal_date, type \\ :fixed)

View Source

Specs

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

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

The type parameter determines the type of the returned value:

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

Examples

  iex>Elixir.SaudiIslamic.as_type(730739)
  730739
  iex>Elixir.SaudiIslamic.as_type(730739, :fixed)
  730739
  iex>Elixir.SaudiIslamic.as_type(730739, :date)
  {1422, 6, 23}
  iex>Elixir.SaudiIslamic.as_type({1422, 6, 23})
  730739
  iex>Elixir.SaudiIslamic.as_type({1422, 6, 23}, :fixed)
  730739
  iex>Elixir.SaudiIslamic.as_type({1422, 6, 23}, :date)
  {1422, 6, 23}

Specs

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

Compares two SaudiIslamic 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.SaudiIslamic.compare({1422, 6, 23}, {1422, 6, 23})
  :eq
  iex>Elixir.SaudiIslamic.compare({1422, 6, 23}, {1422, 10, 5})
  :lt
  iex>Elixir.SaudiIslamic.compare({1422, 10, 5}, {1422, 6, 23})
  :gt

Specs

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

Example

  iex>Elixir.SaudiIslamic.date(1422, 6, 23)
  {1422, 6, 23}
Link to this function

date_diff(cal_date1, cal_date2)

View Source

Specs

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

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

day(cal_date, type \\ :value)

View Source

Specs

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

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

  iex>Elixir.SaudiIslamic.day({1422, 6, 23})
  23
  iex>Elixir.SaudiIslamic.day({1422, 6, 23}, :atom)
  :day
  iex>Elixir.SaudiIslamic.day({1422, 6, 23}, :index)
  2
  iex>Elixir.SaudiIslamic.day({1422, 6, 23}, :name)
  "Day"
  iex>Elixir.SaudiIslamic.day({1422, 6, 23}, :value)
  23

Specs

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

Examples

  iex>Elixir.SaudiIslamic.eq({1422, 6, 23}, {1422, 6, 23})
  true
  iex>Elixir.SaudiIslamic.eq({1422, 6, 23}, {1422, 10, 5})
  false
  iex>Elixir.SaudiIslamic.eq({1422, 10, 5}, {1422, 6, 23})
  false

Specs

field_atom(integer()) :: atom()

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

Examples

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

Specs

field_atoms() :: [atom()]

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

Example

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

Specs

field_count() :: integer()

Returns the number of fields in a SaudiIslamic date

Example

  iex>Elixir.SaudiIslamic.field_count()
  3

Specs

field_index(atom()) :: integer()

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

Examples

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

from_date(other_date, other_calendar)

View Source

Specs

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

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

Example

  iex>Elixir.SaudiIslamic.from_date({2001, 9, 11}, Gregorian)
  {1422, 6, 23}

Specs

from_fixed(fixed()) :: saudi_islamic_date()

Converts a fixed day to a SaudiIslamic date.

Example

  iex>Elixir.SaudiIslamic.from_fixed(730739)
  {1422, 6, 23}

Specs

from_jd(tuple() | number()) :: saudi_islamic_date()

Converts a Julian Day into the equivalent SaudiIslamic date.

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

Examples

  iex>Elixir.SaudiIslamic.from_jd({2452163.5})
  {1422, 6, 23}
  iex>Elixir.SaudiIslamic.from_jd(2452163.5)
  {1422, 6, 23}

Specs

from_rata_die(tuple() | integer()) :: saudi_islamic_date()

Converts a RataDie date into the equivalent SaudiIslamic date.

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

Examples

  iex>Elixir.SaudiIslamic.from_rata_die({730739})
  {1422, 6, 23}
  iex>Elixir.SaudiIslamic.from_rata_die(730739)
  {1422, 6, 23}

Specs

from_unix(tuple() | integer()) :: saudi_islamic_date()

Converts a Unix date into the equivalent SaudiIslamic date.

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

Examples

  iex>Elixir.SaudiIslamic.from_unix({1000166400})
  {1422, 6, 23}
  iex>Elixir.SaudiIslamic.from_unix(1000166400)
  {1422, 6, 23}

Specs

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

Examples

  iex>Elixir.SaudiIslamic.ge({1422, 6, 23}, {1422, 6, 23})
  true
  iex>Elixir.SaudiIslamic.ge({1422, 6, 23}, {1422, 10, 5})
  false
  iex>Elixir.SaudiIslamic.ge({1422, 10, 5}, {1422, 6, 23})
  true

Specs

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

Examples

  iex>Elixir.SaudiIslamic.gt({1422, 6, 23}, {1422, 6, 23})
  false
  iex>Elixir.SaudiIslamic.gt({1422, 6, 23}, {1422, 10, 5})
  false
  iex>Elixir.SaudiIslamic.gt({1422, 10, 5}, {1422, 6, 23})
  true

Specs

keyword() :: atom()

Returns the internal keyword of the SaudiIslamic calendar.

Example

  iex>Elixir.SaudiIslamic.keyword()
  :saudi_islamic

Specs

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

Examples

  iex>Elixir.SaudiIslamic.le({1422, 6, 23}, {1422, 6, 23})
  true
  iex>Elixir.SaudiIslamic.le({1422, 6, 23}, {1422, 10, 5})
  true
  iex>Elixir.SaudiIslamic.le({1422, 10, 5}, {1422, 6, 23})
  false

Specs

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

Examples

  iex>Elixir.SaudiIslamic.lt({1422, 6, 23}, {1422, 6, 23})
  false
  iex>Elixir.SaudiIslamic.lt({1422, 6, 23}, {1422, 10, 5})
  true
  iex>Elixir.SaudiIslamic.lt({1422, 10, 5}, {1422, 6, 23})
  false

Specs

module() :: module()

Returns the module of the SaudiIslamic calendar.

Example

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

month(cal_date, type \\ :value)

View Source

Specs

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

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

  iex>Elixir.SaudiIslamic.month({1422, 6, 23})
  6
  iex>Elixir.SaudiIslamic.month({1422, 6, 23}, :atom)
  :month
  iex>Elixir.SaudiIslamic.month({1422, 6, 23}, :index)
  1
  iex>Elixir.SaudiIslamic.month({1422, 6, 23}, :name)
  "Month"
  iex>Elixir.SaudiIslamic.month({1422, 6, 23}, :value)
  6

Specs

name() :: atom()

Returns the internal name of the SaudiIslamic calendar.

Example

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

Specs

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

Example

  iex>Elixir.SaudiIslamic.range({1422, 6, 23}, {1422, 10, 5})
  730739..730839

Specs

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

Returns the start of the day in the SaudiIslamic calendar.

Possible return values are:

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

Example

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

to_date(date, other_calendar)

View Source

Specs

to_date(saudi_islamic_date(), module()) :: tuple()

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

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

Example

  iex>Elixir.SaudiIslamic.to_date({1422, 6, 23}, Gregorian)
  {2001, 9, 11}

Specs

to_fixed(saudi_islamic_date()) :: fixed()

Converts a SaudiIslamic date tuple into a fixed day.

Example

  iex>Elixir.SaudiIslamic.to_fixed({1422, 6, 23})
  730739
Link to this function

to_fixed(year, month, day)

View Source

Specs

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

Example

  iex>Elixir.SaudiIslamic.to_fixed(1422, 6, 23)
  730739

Specs

to_jd(saudi_islamic_date()) :: {number()}

Converts a SaudiIslamic date into the equivalent Julian Day.

Example

  iex>Elixir.SaudiIslamic.to_jd({1422, 6, 23})
  {2452163.5}

Specs

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

Example

  iex>Elixir.SaudiIslamic.to_jd(1422, 6, 23)
  {2452163.5}

Specs

to_rata_die(saudi_islamic_date()) :: {integer()}

Converts a SaudiIslamic date into the equivalent RataDie date.

Example

  iex>Elixir.SaudiIslamic.to_rata_die({1422, 6, 23})
  {730739}
Link to this function

to_rata_die(year, month, day)

View Source

Specs

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

Example

  iex>Elixir.SaudiIslamic.to_rata_die(1422, 6, 23)
  {730739}

Specs

to_unix(saudi_islamic_date()) :: {integer()}

Converts a SaudiIslamic date into the equivalent Unix date.

Example

  iex>Elixir.SaudiIslamic.to_unix({1422, 6, 23})
  {1000166400}
Link to this function

to_unix(year, month, day)

View Source

Specs

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

Example

  iex>Elixir.SaudiIslamic.to_unix(1422, 6, 23)
  {1000166400}

Specs

today(:fixed | :date) :: fixed() | saudi_islamic_date()

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

Examples

  Elixir.SaudiIslamic.today()
  730739
  Elixir.SaudiIslamic.today(:fixed)
  730739
  Elixir.SaudiIslamic.today(:date)
  {1422, 6, 23}
Link to this function

year(cal_date, type \\ :value)

View Source

Specs

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

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

  iex>Elixir.SaudiIslamic.year({1422, 6, 23})
  1422
  iex>Elixir.SaudiIslamic.year({1422, 6, 23}, :atom)
  :year
  iex>Elixir.SaudiIslamic.year({1422, 6, 23}, :index)
  0
  iex>Elixir.SaudiIslamic.year({1422, 6, 23}, :name)
  "Year"
  iex>Elixir.SaudiIslamic.year({1422, 6, 23}, :value)
  1422