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