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