MJD (Calendars v0.2.4) View Source

The MJD calendar module.

Link to this section Summary

Functions

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

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

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

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

Compares two MJD dates and returns...

Returns a MJD date from its fields day.

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

Returns the day field of a MJD date.

Returns the epoch of the MJD calendar.

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

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

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

Returns the number of fields in a MJD date

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

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

Converts a fixed day to a MJD date.

Converts a Julian Day into the equivalent MJD date.

Converts a RataDie date into the equivalent MJD date.

Converts a Unix date into the equivalent MJD date.

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

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

Returns the internal keyword of the MJD calendar.

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

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

Returns the module of the MJD calendar.

Returns the internal name of the MJD calendar.

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

Returns the start of the day in the MJD calendar.

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

Converts a MJD date given by day into a fixed day.

Converts a MJD date given by day into the equivalent Julian Day.

Converts a MJD date given by day into the equivalent RataDie date.

Converts a MJD date given by day into the equivalent Unix date.

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

Link to this section Types

Specs

fixed() :: integer()

Specs

mjd_date() :: {mjd_day()}

Specs

mjd_day() :: integer()

Specs

t() :: mjd_date()

Link to this section Functions

Link to this function

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

View Source

Specs

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

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

Examples

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

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

  iex>Elixir.MJD.add_days(730739, 100, :date)
  {52263}
  iex>Elixir.MJD.add_days(730739, -100, :date)
  {52063}

  iex>Elixir.MJD.add_days({52163}, 100)
  730839
  iex>Elixir.MJD.add_days({52163}, -100)
  730639

  iex>Elixir.MJD.add_days({52163}, 100, :fixed)
  730839
  iex>Elixir.MJD.add_days({52163}, -100, :fixed)
  730639

  iex>Elixir.MJD.add_days({52163}, 100, :date)
  {52263}
  iex>Elixir.MJD.add_days({52163}, -100, :date)
  {52063}

Specs

as_date(fixed() | mjd_date()) :: mjd_date()

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

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.MJD.as_date(730739)
  {52163}
  iex>Elixir.MJD.as_date({52163})
  {52163}

Specs

as_fixed(fixed() | mjd_date()) :: fixed()

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

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.MJD.as_fixed(730739)
  730739
  iex>Elixir.MJD.as_fixed({52163})
  730739
Link to this function

as_type(cal_date, type \\ :fixed)

View Source

Specs

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

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

The type parameter determines the type of the returned value:

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

Examples

  iex>Elixir.MJD.as_type(730739)
  730739
  iex>Elixir.MJD.as_type(730739, :fixed)
  730739
  iex>Elixir.MJD.as_type(730739, :date)
  {52163}
  iex>Elixir.MJD.as_type({52163})
  730739
  iex>Elixir.MJD.as_type({52163}, :fixed)
  730739
  iex>Elixir.MJD.as_type({52163}, :date)
  {52163}

Specs

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

Compares two MJD 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.MJD.compare({52163}, {52163})
  :eq
  iex>Elixir.MJD.compare({52163}, {52263})
  :lt
  iex>Elixir.MJD.compare({52263}, {52163})
  :gt

Specs

date(mjd_day()) :: t()

Returns a MJD date from its fields day.

Example

  iex>Elixir.MJD.date(52163)
  {52163}
Link to this function

date_diff(cal_date1, cal_date2)

View Source

Specs

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

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

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

day(cal_date, type \\ :value)

View Source

Specs

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

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

  iex>Elixir.MJD.day({52163})
  52163
  iex>Elixir.MJD.day({52163}, :atom)
  :day
  iex>Elixir.MJD.day({52163}, :index)
  0
  iex>Elixir.MJD.day({52163}, :name)
  "Day"
  iex>Elixir.MJD.day({52163}, :value)
  52163

Specs

epoch() :: number()

Returns the epoch of the MJD calendar.

Example

  iex>Elixir.MJD.epoch()
  678576

Specs

eq(mjd_date(), mjd_date()) :: boolean()

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

Examples

  iex>Elixir.MJD.eq({52163}, {52163})
  true
  iex>Elixir.MJD.eq({52163}, {52263})
  false
  iex>Elixir.MJD.eq({52263}, {52163})
  false

Specs

field_atom(integer()) :: atom()

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

Example

  iex>Elixir.MJD.field_atom(0)
  :day

Specs

field_atoms() :: [atom()]

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

Example

  iex>Elixir.MJD.field_atoms()
  [:day]

Specs

field_count() :: integer()

Returns the number of fields in a MJD date

Example

  iex>Elixir.MJD.field_count()
  1

Specs

field_index(atom()) :: integer()

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

Example

  iex>Elixir.MJD.field_index(:day)
  0
Link to this function

from_date(other_date, other_calendar)

View Source

Specs

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

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

Example

  iex>Elixir.MJD.from_date({2001, 9, 11}, Gregorian)
  {52163}

Specs

from_fixed(fixed()) :: mjd_date()

Converts a fixed day to a MJD date.

Example

  iex>Elixir.MJD.from_fixed(730739)
  {52163}

Specs

from_jd(tuple() | number()) :: mjd_date()

Converts a Julian Day into the equivalent MJD date.

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

Examples

  iex>Elixir.MJD.from_jd({2452163.5})
  {52163}
  iex>Elixir.MJD.from_jd(2452163.5)
  {52163}

Specs

from_rata_die(tuple() | integer()) :: mjd_date()

Converts a RataDie date into the equivalent MJD date.

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

Examples

  iex>Elixir.MJD.from_rata_die({730739})
  {52163}
  iex>Elixir.MJD.from_rata_die(730739)
  {52163}

Specs

from_unix(tuple() | integer()) :: mjd_date()

Converts a Unix date into the equivalent MJD date.

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

Examples

  iex>Elixir.MJD.from_unix({1000166400})
  {52163}
  iex>Elixir.MJD.from_unix(1000166400)
  {52163}

Specs

ge(mjd_date(), mjd_date()) :: boolean()

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

Examples

  iex>Elixir.MJD.ge({52163}, {52163})
  true
  iex>Elixir.MJD.ge({52163}, {52263})
  false
  iex>Elixir.MJD.ge({52263}, {52163})
  true

Specs

gt(mjd_date(), mjd_date()) :: boolean()

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

Examples

  iex>Elixir.MJD.gt({52163}, {52163})
  false
  iex>Elixir.MJD.gt({52163}, {52263})
  false
  iex>Elixir.MJD.gt({52263}, {52163})
  true

Specs

keyword() :: atom()

Returns the internal keyword of the MJD calendar.

Example

  iex>Elixir.MJD.keyword()
  :mjd

Specs

le(mjd_date(), mjd_date()) :: boolean()

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

Examples

  iex>Elixir.MJD.le({52163}, {52163})
  true
  iex>Elixir.MJD.le({52163}, {52263})
  true
  iex>Elixir.MJD.le({52263}, {52163})
  false

Specs

lt(mjd_date(), mjd_date()) :: boolean()

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

Examples

  iex>Elixir.MJD.lt({52163}, {52163})
  false
  iex>Elixir.MJD.lt({52163}, {52263})
  true
  iex>Elixir.MJD.lt({52263}, {52163})
  false

Specs

module() :: module()

Returns the module of the MJD calendar.

Example

  iex>Elixir.MJD.module()
  MJD

Specs

name() :: atom()

Returns the internal name of the MJD calendar.

Example

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

Specs

range(mjd_date(), mjd_date()) :: integer()

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

Example

  iex>Elixir.MJD.range({52163}, {52263})
  730739..730839

Specs

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

Returns the start of the day in the MJD calendar.

Possible return values are:

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

Example

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

to_date(date, other_calendar)

View Source

Specs

to_date(mjd_date(), module()) :: tuple()

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

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

Example

  iex>Elixir.MJD.to_date({52163}, Gregorian)
  {2001, 9, 11}

Specs

to_fixed(mjd_date()) :: fixed()
to_fixed(mjd_day()) :: fixed()

Converts a MJD date given by day into a fixed day.

Example

  iex>Elixir.MJD.to_fixed(52163)
  730739

Specs

to_jd(mjd_date()) :: {number()}
to_jd(mjd_day()) :: {number()}

Converts a MJD date given by day into the equivalent Julian Day.

Example

  iex>Elixir.MJD.to_jd(52163)
  {2452163.5}

Specs

to_rata_die(mjd_date()) :: {integer()}
to_rata_die(mjd_day()) :: {integer()}

Converts a MJD date given by day into the equivalent RataDie date.

Example

  iex>Elixir.MJD.to_rata_die(52163)
  {730739}

Specs

to_unix(mjd_date()) :: {integer()}
to_unix(mjd_day()) :: {integer()}

Converts a MJD date given by day into the equivalent Unix date.

Example

  iex>Elixir.MJD.to_unix(52163)
  {1000166400}

Specs

today(:fixed | :date) :: fixed() | mjd_date()

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

Examples

  Elixir.MJD.today()
  730739
  Elixir.MJD.today(:fixed)
  730739
  Elixir.MJD.today(:date)
  {52163}