Samaritan (Calendars v0.2.4) View Source

The Samaritan calendar module.

Link to this section Summary

Functions

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

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

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

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

Compares two Samaritan dates and returns...

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

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

Returns the day field of a Samaritan date.

Returns the epoch of the Samaritan calendar.

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

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

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

Returns the number of fields in a Samaritan date

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

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

Converts a fixed day to a Samaritan date.

Converts a Julian Day into the equivalent Samaritan date.

Converts a RataDie date into the equivalent Samaritan date.

Converts a Unix date into the equivalent Samaritan date.

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

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

Returns the internal keyword of the Samaritan calendar.

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

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

Returns the module of the Samaritan calendar.

Returns the month field of a Samaritan date.

Returns the internal name of the Samaritan calendar.

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

Returns the start of the day in the Samaritan calendar.

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

Converts a Samaritan date tuple into a fixed day.

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

Converts a Samaritan date into the equivalent Julian Day.

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

Converts a Samaritan date into the equivalent RataDie date.

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

Converts a Samaritan date into the equivalent Unix date.

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

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

Returns the year field of a Samaritan date.

Link to this section Types

Specs

fixed() :: integer()

Specs

samaritan_date() :: {samaritan_year(), samaritan_month(), samaritan_day()}

Specs

samaritan_day() :: 1..30

Specs

samaritan_month() :: 1..12

Specs

samaritan_year() :: :integer

Specs

t() :: samaritan_date()

Link to this section Functions

Link to this function

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

View Source

Specs

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

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

Examples

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

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

  iex>Elixir.Samaritan.add_days(730739, 100, :date)
  {3640, 10, 6}
  iex>Elixir.Samaritan.add_days(730739, -100, :date)
  {3639, 3, 12}

  iex>Elixir.Samaritan.add_days({3640, 6, 24}, 100)
  730839
  iex>Elixir.Samaritan.add_days({3640, 6, 24}, -100)
  730639

  iex>Elixir.Samaritan.add_days({3640, 6, 24}, 100, :fixed)
  730839
  iex>Elixir.Samaritan.add_days({3640, 6, 24}, -100, :fixed)
  730639

  iex>Elixir.Samaritan.add_days({3640, 6, 24}, 100, :date)
  {3640, 10, 6}
  iex>Elixir.Samaritan.add_days({3640, 6, 24}, -100, :date)
  {3639, 3, 12}

Specs

as_date(fixed() | samaritan_date()) :: samaritan_date()

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

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.Samaritan.as_date(730739)
  {3640, 6, 24}
  iex>Elixir.Samaritan.as_date({3640, 6, 24})
  {3640, 6, 24}

Specs

as_fixed(fixed() | samaritan_date()) :: fixed()

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

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.Samaritan.as_fixed(730739)
  730739
  iex>Elixir.Samaritan.as_fixed({3640, 6, 24})
  730739
Link to this function

as_type(cal_date, type \\ :fixed)

View Source

Specs

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

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

The type parameter determines the type of the returned value:

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

Examples

  iex>Elixir.Samaritan.as_type(730739)
  730739
  iex>Elixir.Samaritan.as_type(730739, :fixed)
  730739
  iex>Elixir.Samaritan.as_type(730739, :date)
  {3640, 6, 24}
  iex>Elixir.Samaritan.as_type({3640, 6, 24})
  730739
  iex>Elixir.Samaritan.as_type({3640, 6, 24}, :fixed)
  730739
  iex>Elixir.Samaritan.as_type({3640, 6, 24}, :date)
  {3640, 6, 24}

Specs

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

Compares two Samaritan 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.Samaritan.compare({3640, 6, 24}, {3640, 6, 24})
  :eq
  iex>Elixir.Samaritan.compare({3640, 6, 24}, {3640, 10, 6})
  :lt
  iex>Elixir.Samaritan.compare({3640, 10, 6}, {3640, 6, 24})
  :gt

Specs

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

Example

  iex>Elixir.Samaritan.date(3640, 6, 24)
  {3640, 6, 24}
Link to this function

date_diff(cal_date1, cal_date2)

View Source

Specs

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

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

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

day(cal_date, type \\ :value)

View Source

Specs

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

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

  iex>Elixir.Samaritan.day({3640, 6, 24})
  24
  iex>Elixir.Samaritan.day({3640, 6, 24}, :atom)
  :day
  iex>Elixir.Samaritan.day({3640, 6, 24}, :index)
  2
  iex>Elixir.Samaritan.day({3640, 6, 24}, :name)
  "Day"
  iex>Elixir.Samaritan.day({3640, 6, 24}, :value)
  24

Specs

epoch() :: number()

Returns the epoch of the Samaritan calendar.

Example

  iex>Elixir.Samaritan.epoch()
  -598573

Specs

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

Examples

  iex>Elixir.Samaritan.eq({3640, 6, 24}, {3640, 6, 24})
  true
  iex>Elixir.Samaritan.eq({3640, 6, 24}, {3640, 10, 6})
  false
  iex>Elixir.Samaritan.eq({3640, 10, 6}, {3640, 6, 24})
  false

Specs

field_atom(integer()) :: atom()

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

Examples

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

Specs

field_atoms() :: [atom()]

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

Example

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

Specs

field_count() :: integer()

Returns the number of fields in a Samaritan date

Example

  iex>Elixir.Samaritan.field_count()
  3

Specs

field_index(atom()) :: integer()

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

Examples

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

from_date(other_date, other_calendar)

View Source

Specs

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

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

Example

  iex>Elixir.Samaritan.from_date({2001, 9, 11}, Gregorian)
  {3640, 6, 24}

Specs

from_fixed(fixed()) :: samaritan_date()

Converts a fixed day to a Samaritan date.

Example

  iex>Elixir.Samaritan.from_fixed(730739)
  {3640, 6, 24}

Specs

from_jd(tuple() | number()) :: samaritan_date()

Converts a Julian Day into the equivalent Samaritan date.

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

Examples

  iex>Elixir.Samaritan.from_jd({2452163.5})
  {3640, 6, 24}
  iex>Elixir.Samaritan.from_jd(2452163.5)
  {3640, 6, 24}

Specs

from_rata_die(tuple() | integer()) :: samaritan_date()

Converts a RataDie date into the equivalent Samaritan date.

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

Examples

  iex>Elixir.Samaritan.from_rata_die({730739})
  {3640, 6, 24}
  iex>Elixir.Samaritan.from_rata_die(730739)
  {3640, 6, 24}

Specs

from_unix(tuple() | integer()) :: samaritan_date()

Converts a Unix date into the equivalent Samaritan date.

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

Examples

  iex>Elixir.Samaritan.from_unix({1000166400})
  {3640, 6, 24}
  iex>Elixir.Samaritan.from_unix(1000166400)
  {3640, 6, 24}

Specs

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

Examples

  iex>Elixir.Samaritan.ge({3640, 6, 24}, {3640, 6, 24})
  true
  iex>Elixir.Samaritan.ge({3640, 6, 24}, {3640, 10, 6})
  false
  iex>Elixir.Samaritan.ge({3640, 10, 6}, {3640, 6, 24})
  true

Specs

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

Examples

  iex>Elixir.Samaritan.gt({3640, 6, 24}, {3640, 6, 24})
  false
  iex>Elixir.Samaritan.gt({3640, 6, 24}, {3640, 10, 6})
  false
  iex>Elixir.Samaritan.gt({3640, 10, 6}, {3640, 6, 24})
  true

Specs

keyword() :: atom()

Returns the internal keyword of the Samaritan calendar.

Example

  iex>Elixir.Samaritan.keyword()
  :samaritan

Specs

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

Examples

  iex>Elixir.Samaritan.le({3640, 6, 24}, {3640, 6, 24})
  true
  iex>Elixir.Samaritan.le({3640, 6, 24}, {3640, 10, 6})
  true
  iex>Elixir.Samaritan.le({3640, 10, 6}, {3640, 6, 24})
  false

Specs

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

Examples

  iex>Elixir.Samaritan.lt({3640, 6, 24}, {3640, 6, 24})
  false
  iex>Elixir.Samaritan.lt({3640, 6, 24}, {3640, 10, 6})
  true
  iex>Elixir.Samaritan.lt({3640, 10, 6}, {3640, 6, 24})
  false

Specs

module() :: module()

Returns the module of the Samaritan calendar.

Example

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

month(cal_date, type \\ :value)

View Source

Specs

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

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

  iex>Elixir.Samaritan.month({3640, 6, 24})
  6
  iex>Elixir.Samaritan.month({3640, 6, 24}, :atom)
  :month
  iex>Elixir.Samaritan.month({3640, 6, 24}, :index)
  1
  iex>Elixir.Samaritan.month({3640, 6, 24}, :name)
  "Month"
  iex>Elixir.Samaritan.month({3640, 6, 24}, :value)
  6

Specs

name() :: atom()

Returns the internal name of the Samaritan calendar.

Example

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

Specs

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

Example

  iex>Elixir.Samaritan.range({3640, 6, 24}, {3640, 10, 6})
  730739..730839

Specs

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

Returns the start of the day in the Samaritan calendar.

Possible return values are:

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

Example

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

to_date(date, other_calendar)

View Source

Specs

to_date(samaritan_date(), module()) :: tuple()

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

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

Example

  iex>Elixir.Samaritan.to_date({3640, 6, 24}, Gregorian)
  {2001, 9, 11}

Specs

to_fixed(samaritan_date()) :: fixed()

Converts a Samaritan date tuple into a fixed day.

Example

  iex>Elixir.Samaritan.to_fixed({3640, 6, 24})
  730739
Link to this function

to_fixed(year, month, day)

View Source

Specs

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

Example

  iex>Elixir.Samaritan.to_fixed(3640, 6, 24)
  730739

Specs

to_jd(samaritan_date()) :: {number()}

Converts a Samaritan date into the equivalent Julian Day.

Example

  iex>Elixir.Samaritan.to_jd({3640, 6, 24})
  {2452163.5}

Specs

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

Example

  iex>Elixir.Samaritan.to_jd(3640, 6, 24)
  {2452163.5}

Specs

to_rata_die(samaritan_date()) :: {integer()}

Converts a Samaritan date into the equivalent RataDie date.

Example

  iex>Elixir.Samaritan.to_rata_die({3640, 6, 24})
  {730739}
Link to this function

to_rata_die(year, month, day)

View Source

Specs

to_rata_die(samaritan_year(), samaritan_month(), samaritan_day()) :: {integer()}

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

Example

  iex>Elixir.Samaritan.to_rata_die(3640, 6, 24)
  {730739}

Specs

to_unix(samaritan_date()) :: {integer()}

Converts a Samaritan date into the equivalent Unix date.

Example

  iex>Elixir.Samaritan.to_unix({3640, 6, 24})
  {1000166400}
Link to this function

to_unix(year, month, day)

View Source

Specs

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

Example

  iex>Elixir.Samaritan.to_unix(3640, 6, 24)
  {1000166400}

Specs

today(:fixed | :date) :: fixed() | samaritan_date()

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

Examples

  Elixir.Samaritan.today()
  730739
  Elixir.Samaritan.today(:fixed)
  730739
  Elixir.Samaritan.today(:date)
  {3640, 6, 24}
Link to this function

year(cal_date, type \\ :value)

View Source

Specs

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

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

  iex>Elixir.Samaritan.year({3640, 6, 24})
  3640
  iex>Elixir.Samaritan.year({3640, 6, 24}, :atom)
  :year
  iex>Elixir.Samaritan.year({3640, 6, 24}, :index)
  0
  iex>Elixir.Samaritan.year({3640, 6, 24}, :name)
  "Year"
  iex>Elixir.Samaritan.year({3640, 6, 24}, :value)
  3640