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