JD (Calendars v0.2.4) View Source
The JD
calendar module.
Link to this section Summary
Functions
Adds the number of days
to a fixed day or JD date.
Returns a fixed day or JD date as a JD date.
Returns a fixed day or JD date as a fixed day.
Returns a fixed day or JD date either as a fixed day or a JD date.
Compares two JD dates and returns...
Returns a JD date from its fields day
.
Returns the difference (= number of days) between two JD dates.
Returns the day
field of a JD date.
Returns the epoch of the JD calendar.
Returns true if JD date1
is equal JD date2
, otherwise false.
Returns the name of the field atom in a JD date at field_index
.
Returns a list of the field atoms (names) of a JD date.
Returns the number of fields in a JD date
Returns the index (= position) of the field_atom
in a JD date.
Converts the other_date
of the other_calendar
into the equivalent date of the JD calendar.
Converts a fixed day to a JD
date.
Converts a RataDie date into the equivalent JD date.
Converts a Unix date into the equivalent JD date.
Returns true if JD date1
is greater (= later) than or equal JD date2
, otherwise false.
Returns true if JD date1
is greater (= later) than JD date2
, otherwise false.
Returns the internal keyword of the JD calendar.
Returns true if JD date1
is smaller (= earlier) than or equal JD date2
, otherwise false.
Returns true if JD date1
is smaller (= earlier) than JD date2
, otherwise false.
Returns the module of the JD calendar.
Returns the internal name of the JD calendar.
Returns the distance between two JD dates as a range of fixed days.
Returns the start of the day in the JD calendar.
Converts a JD date
into the equivalent date
of the other_calendar
.
Converts a JD date given by day
into a fixed day.
Converts a JD date given by day
into the equivalent RataDie date.
Converts a JD date given by day
into the equivalent Unix date.
Returns the current date either as a fixed day or a JD date.
Link to this section Types
Link to this section Functions
Specs
Adds the number of days
to a fixed day or JD 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 JD date.
Examples
iex>Elixir.JD.add_days(730739, 100)
730839
iex>Elixir.JD.add_days(730739, -100)
730639
iex>Elixir.JD.add_days(730739, 100, :fixed)
730839
iex>Elixir.JD.add_days(730739, -100, :fixed)
730639
iex>Elixir.JD.add_days(730739, 100, :date)
{2452263.5}
iex>Elixir.JD.add_days(730739, -100, :date)
{2452063.5}
iex>Elixir.JD.add_days({2452163.5}, 100)
730839
iex>Elixir.JD.add_days({2452163.5}, -100)
730639
iex>Elixir.JD.add_days({2452163.5}, 100, :fixed)
730839
iex>Elixir.JD.add_days({2452163.5}, -100, :fixed)
730639
iex>Elixir.JD.add_days({2452163.5}, 100, :date)
{2452263.5}
iex>Elixir.JD.add_days({2452163.5}, -100, :date)
{2452063.5}
Specs
Returns a fixed day or JD date as a JD date.
This is a convenience function to simplify certain function calls.
Examples
iex>Elixir.JD.as_date(730739)
{2452163.5}
iex>Elixir.JD.as_date({2452163.5})
{2452163.5}
Specs
Returns a fixed day or JD date as a fixed day.
This is a convenience function to simplify certain function calls.
Examples
iex>Elixir.JD.as_fixed(730739)
730739
iex>Elixir.JD.as_fixed({2452163.5})
730739
Specs
Returns a fixed day or JD date either as a fixed day or a JD date.
The type
parameter determines the type of the returned value:
:fixed
returns a fixed day (default),:date
returns a JD date.
Examples
iex>Elixir.JD.as_type(730739)
730739
iex>Elixir.JD.as_type(730739, :fixed)
730739
iex>Elixir.JD.as_type(730739, :date)
{2452163.5}
iex>Elixir.JD.as_type({2452163.5})
730739
iex>Elixir.JD.as_type({2452163.5}, :fixed)
730739
iex>Elixir.JD.as_type({2452163.5}, :date)
{2452163.5}
Specs
Compares two JD dates and returns...
:lt
ifdate1
is smaller (= earlier) thandate2
,:eq
ifdate1
is equaldate2
,:gt
ifdate1
is larger (= later) thandate2
.
Examples
iex>Elixir.JD.compare({2452163.5}, {2452163.5})
:eq
iex>Elixir.JD.compare({2452163.5}, {2452263.5})
:lt
iex>Elixir.JD.compare({2452263.5}, {2452163.5})
:gt
Specs
Returns a JD date from its fields day
.
Example
iex>Elixir.JD.date(2452163.5)
{2452163.5}
Specs
Returns the difference (= number of days) between two JD dates.
The dates can be given as fixed days or JD 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.JD.date_diff(730739, 730839)
100
iex>Elixir.JD.date_diff(730839, 730739)
-100
iex>Elixir.JD.date_diff({2452163.5}, {2452263.5})
100
iex>Elixir.JD.date_diff({2452263.5}, {2452163.5})
-100
iex>Elixir.JD.date_diff(730739, {2452263.5})
100
iex>Elixir.JD.date_diff({2452163.5}, 730839)
100
Specs
day(fixed() | jd_date(), :atom | :index | :name | :value) :: :atom | integer() | String.t() | number()
Returns the day
field of a JD 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.JD.day(730739)
2452163.5
iex>Elixir.JD.day(730739, :atom)
:day
iex>Elixir.JD.day(730739, :index)
0
iex>Elixir.JD.day(730739, :name)
"Day"
iex>Elixir.JD.day(730739, :value)
2452163.5
iex>Elixir.JD.day({2452163.5})
2452163.5
iex>Elixir.JD.day({2452163.5}, :atom)
:day
iex>Elixir.JD.day({2452163.5}, :index)
0
iex>Elixir.JD.day({2452163.5}, :name)
"Day"
iex>Elixir.JD.day({2452163.5}, :value)
2452163.5
Specs
epoch() :: number()
Returns the epoch of the JD calendar.
Example
iex>Elixir.JD.epoch()
-1721424.5
Specs
Returns true if JD date1
is equal JD date2
, otherwise false.
Examples
iex>Elixir.JD.eq({2452163.5}, {2452163.5})
true
iex>Elixir.JD.eq({2452163.5}, {2452263.5})
false
iex>Elixir.JD.eq({2452263.5}, {2452163.5})
false
Specs
Returns the name of the field atom in a JD date at field_index
.
Example
iex>Elixir.JD.field_atom(0)
:day
Specs
field_atoms() :: [atom()]
Returns a list of the field atoms (names) of a JD date.
Example
iex>Elixir.JD.field_atoms()
[:day]
Specs
field_count() :: integer()
Returns the number of fields in a JD date
Example
iex>Elixir.JD.field_count()
1
Specs
Returns the index (= position) of the field_atom
in a JD date.
Example
iex>Elixir.JD.field_index(:day)
0
Specs
Converts the other_date
of the other_calendar
into the equivalent date of the JD calendar.
Example
iex>Elixir.JD.from_date({2001, 9, 11}, Gregorian)
{2452163.5}
Specs
Converts a fixed day to a JD
date.
Example
iex>Elixir.JD.from_fixed(730739)
{2452163.5}
Specs
Converts a RataDie date into the equivalent JD date.
The RataDie date can be given as a tuple or by a RataDie rd
.
Examples
iex>Elixir.JD.from_rata_die({730739})
{2452163.5}
iex>Elixir.JD.from_rata_die(730739)
{2452163.5}
Specs
Converts a Unix date into the equivalent JD date.
The Unix date can be given as a tuple or by Unix seconds
.
Examples
iex>Elixir.JD.from_unix({1000166400})
{2452163.5}
iex>Elixir.JD.from_unix(1000166400)
{2452163.5}
Specs
Returns true if JD date1
is greater (= later) than or equal JD date2
, otherwise false.
Examples
iex>Elixir.JD.ge({2452163.5}, {2452163.5})
true
iex>Elixir.JD.ge({2452163.5}, {2452263.5})
false
iex>Elixir.JD.ge({2452263.5}, {2452163.5})
true
Specs
Returns true if JD date1
is greater (= later) than JD date2
, otherwise false.
Examples
iex>Elixir.JD.gt({2452163.5}, {2452163.5})
false
iex>Elixir.JD.gt({2452163.5}, {2452263.5})
false
iex>Elixir.JD.gt({2452263.5}, {2452163.5})
true
Specs
keyword() :: atom()
Returns the internal keyword of the JD calendar.
Example
iex>Elixir.JD.keyword()
:jd
Specs
Returns true if JD date1
is smaller (= earlier) than or equal JD date2
, otherwise false.
Examples
iex>Elixir.JD.le({2452163.5}, {2452163.5})
true
iex>Elixir.JD.le({2452163.5}, {2452263.5})
true
iex>Elixir.JD.le({2452263.5}, {2452163.5})
false
Specs
Returns true if JD date1
is smaller (= earlier) than JD date2
, otherwise false.
Examples
iex>Elixir.JD.lt({2452163.5}, {2452163.5})
false
iex>Elixir.JD.lt({2452163.5}, {2452263.5})
true
iex>Elixir.JD.lt({2452263.5}, {2452163.5})
false
Specs
module() :: module()
Returns the module of the JD calendar.
Example
iex>Elixir.JD.module()
JD
Specs
name() :: atom()
Returns the internal name of the JD calendar.
Example
iex>Elixir.JD.name()
"JD"
Specs
Returns the distance between two JD dates as a range of fixed days.
Example
iex>Elixir.JD.range({2452163.5}, {2452263.5})
730739..730839
Specs
start_of_day() :: :midnight | :sunset | :sunrise | :noon
Returns the start of the day in the JD calendar.
Possible return values are:
:midnight
,:noon
,:sunrise
,:sunset
,
Example
iex>Elixir.JD.start_of_day()
:noon
Specs
Converts a JD date
into the equivalent date
of the other_calendar
.
For the following example to work the Gregorian calendar must be available.
Example
iex>Elixir.JD.to_date({2452163.5}, Gregorian)
{2001, 9, 11}
Specs
Converts a JD date given by day
into a fixed day.
Example
iex>Elixir.JD.to_fixed(2452163.5)
730739
Specs
Converts a JD date given by day
into the equivalent RataDie date.
Example
iex>Elixir.JD.to_rata_die(2452163.5)
{730739}
Specs
Converts a JD date given by day
into the equivalent Unix date.
Example
iex>Elixir.JD.to_unix(2452163.5)
{1000166400}
Specs
Returns the current date either as a fixed day or a JD 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 JD date.
Examples
Elixir.JD.today()
730739
Elixir.JD.today(:fixed)
730739
Elixir.JD.today(:date)
{2452163.5}