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

Specs

fixed() :: integer()

Specs

iso_date() :: {iso_year(), iso_week(), iso_day()}

Specs

iso_day() :: 1..7

Specs

iso_week() :: 1..53

Specs

iso_year() :: integer()

Specs

t() :: iso_date()

Link to this section Functions

Link to this function

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

View Source

Specs

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

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

as_date(fixed() | iso_date()) :: iso_date()

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

as_fixed(fixed() | iso_date()) :: fixed()

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
Link to this function

as_type(cal_date, type \\ :fixed)

View Source

Specs

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

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

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

Compares two ISO 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.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

date(iso_year(), iso_week(), iso_day()) :: t()

Returns a ISO date from its fields year, week, day.

Example

  iex>Elixir.ISO.date(2001, 37, 2)
  {2001, 37, 2}
Link to this function

date_diff(cal_date1, cal_date2)

View Source

Specs

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

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
Link to this function

day(cal_date, type \\ :value)

View Source

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

eq(iso_date(), iso_date()) :: boolean()

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

field_atom(integer()) :: atom()

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

field_index(atom()) :: integer()

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
Link to this function

from_date(other_date, other_calendar)

View Source

Specs

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

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

from_fixed(fixed()) :: iso_date()

Converts a fixed day to a ISO date.

Example

  iex>Elixir.ISO.from_fixed(730739)
  {2001, 37, 2}

Specs

from_jd(tuple() | number()) :: iso_date()

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

from_rata_die(tuple() | integer()) :: iso_date()

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

from_unix(tuple() | integer()) :: iso_date()

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

ge(iso_date(), iso_date()) :: boolean()

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

gt(iso_date(), iso_date()) :: boolean()

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

le(iso_date(), iso_date()) :: boolean()

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

long_year?(iso_year()) :: boolean()

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

lt(iso_date(), iso_date()) :: boolean()

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

range(iso_date(), iso_date()) :: integer()

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
Link to this function

to_date(date, other_calendar)

View Source

Specs

to_date(iso_date(), module()) :: tuple()

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

to_fixed(iso_date()) :: fixed()

Converts a ISO date tuple into a fixed day.

Example

  iex>Elixir.ISO.to_fixed({2001, 37, 2})
  730739
Link to this function

to_fixed(year, week, day)

View Source

Specs

to_fixed(iso_year(), iso_week(), iso_day()) :: fixed()

Converts a ISO date given by year, week, day into a fixed day.

Example

  iex>Elixir.ISO.to_fixed(2001, 37, 2)
  730739

Specs

to_jd(iso_date()) :: {number()}

Converts a ISO date into the equivalent Julian Day.

Example

  iex>Elixir.ISO.to_jd({2001, 37, 2})
  {2452163.5}

Specs

to_jd(iso_year(), iso_week(), iso_day()) :: {number()}

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

to_rata_die(iso_date()) :: {integer()}

Converts a ISO date into the equivalent RataDie date.

Example

  iex>Elixir.ISO.to_rata_die({2001, 37, 2})
  {730739}
Link to this function

to_rata_die(year, week, day)

View Source

Specs

to_rata_die(iso_year(), iso_week(), iso_day()) :: {integer()}

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

to_unix(iso_date()) :: {integer()}

Converts a ISO date into the equivalent Unix date.

Example

  iex>Elixir.ISO.to_unix({2001, 37, 2})
  {1000166400}
Link to this function

to_unix(year, week, day)

View Source

Specs

to_unix(iso_year(), iso_week(), iso_day()) :: {integer()}

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

today(:fixed | :date) :: fixed() | iso_date()

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}
Link to this function

week(cal_date, type \\ :value)

View Source

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
Link to this function

year(cal_date, type \\ :value)

View Source

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