Roman (Calendars v0.2.4) View Source

The Roman calendar module.

Link to this section Summary

Functions

Adds the number of days to a fixed day or Roman date.

Returns a fixed day or Roman date as a Roman date.

Returns a fixed day or Roman date as a fixed day.

Returns a fixed day or Roman date either as a fixed day or a Roman date.

Compares two Roman dates and returns...

Returns the count field of a Roman date.

Returns a Roman date from its fields year, month, event, count, leap.

Returns the difference (= number of days) between two Roman dates.

Returns true if Roman date1 is equal Roman date2, otherwise false.

Returns the event field of a Roman date.

Returns the name of the field atom in a Roman date at field_index.

Returns a list of the field atoms (names) of a Roman date.

Returns the number of fields in a Roman date

Returns the index (= position) of the field_atom in a Roman date.

Converts the other_date of the other_calendar into the equivalent date of the Roman calendar.

Converts a fixed day to a Roman date.

Converts a Julian Day into the equivalent Roman date.

Converts a RataDie date into the equivalent Roman date.

Converts a Unix date into the equivalent Roman date.

Returns true if Roman date1 is greater (= later) than or equal Roman date2, otherwise false.

Returns true if Roman date1 is greater (= later) than Roman date2, otherwise false.

Returns the internal keyword of the Roman calendar.

Returns true if Roman date1 is smaller (= earlier) than or equal Roman date2, otherwise false.

Returns the leap field of a Roman date.

Returns true if Roman date1 is smaller (= earlier) than Roman date2, otherwise false.

Returns the module of the Roman calendar.

Returns the month field of a Roman date.

Returns the internal name of the Roman calendar.

Returns the distance between two Roman dates as a range of fixed days.

Returns the start of the day in the Roman calendar.

Converts a Roman date into the equivalent date of the other_calendar.

Converts a Roman date tuple into a fixed day.

Converts a Roman date given by year, month, event, count, leap into a fixed day.

Converts a Roman date into the equivalent Julian Day.

Converts a Roman date given by year, month, event, count, leap into the equivalent Julian Day.

Converts a Roman date into the equivalent RataDie date.

Converts a Roman date given by year, month, event, count, leap into the equivalent RataDie date.

Converts a Roman date into the equivalent Unix date.

Converts a Roman date given by year, month, event, count, leap into the equivalent Unix date.

Returns the current date either as a fixed day or a Roman date.

Returns the year field of a Roman date.

Link to this section Types

Specs

fixed() :: integer()

Specs

roman_count() :: 1..19

Specs

roman_date() ::
  {roman_year(), roman_month(), roman_event(), roman_count(), roman_leap()}

Specs

roman_event() :: 1..3

Specs

roman_leap() :: :boolean

Specs

roman_month() :: 1..12

Specs

roman_year() :: :non_zero_integer

Specs

t() :: roman_date()

Link to this section Functions

Link to this function

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

View Source

Specs

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

Adds the number of days to a fixed day or Roman 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 Roman date.

Examples

  iex>Elixir.Roman.add_days(730739, 100)
  730839
  iex>Elixir.Roman.add_days(730739, -100)
  730639

  iex>Elixir.Roman.add_days(730739, 100, :fixed)
  730839
  iex>Elixir.Roman.add_days(730739, -100, :fixed)
  730639

  iex>Elixir.Roman.add_days(730739, 100, :date)
  {2001, 12, 3, 7, false}
  iex>Elixir.Roman.add_days(730739, -100, :date)
  {2001, 6, 1, 12, false}

  iex>Elixir.Roman.add_days({2001, 9, 1, 4, false}, 100)
  730839
  iex>Elixir.Roman.add_days({2001, 9, 1, 4, false}, -100)
  730639

  iex>Elixir.Roman.add_days({2001, 9, 1, 4, false}, 100, :fixed)
  730839
  iex>Elixir.Roman.add_days({2001, 9, 1, 4, false}, -100, :fixed)
  730639

  iex>Elixir.Roman.add_days({2001, 9, 1, 4, false}, 100, :date)
  {2001, 12, 3, 7, false}
  iex>Elixir.Roman.add_days({2001, 9, 1, 4, false}, -100, :date)
  {2001, 6, 1, 12, false}

Specs

as_date(fixed() | roman_date()) :: roman_date()

Returns a fixed day or Roman date as a Roman date.

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.Roman.as_date(730739)
  {2001, 9, 1, 4, false}
  iex>Elixir.Roman.as_date({2001, 9, 1, 4, false})
  {2001, 9, 1, 4, false}

Specs

as_fixed(fixed() | roman_date()) :: fixed()

Returns a fixed day or Roman date as a fixed day.

This is a convenience function to simplify certain function calls.

Examples

  iex>Elixir.Roman.as_fixed(730739)
  730739
  iex>Elixir.Roman.as_fixed({2001, 9, 1, 4, false})
  730739
Link to this function

as_type(cal_date, type \\ :fixed)

View Source

Specs

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

Returns a fixed day or Roman date either as a fixed day or a Roman date.

The type parameter determines the type of the returned value:

  • :fixed returns a fixed day (default),
  • :date returns a Roman date.

Examples

  iex>Elixir.Roman.as_type(730739)
  730739
  iex>Elixir.Roman.as_type(730739, :fixed)
  730739
  iex>Elixir.Roman.as_type(730739, :date)
  {2001, 9, 1, 4, false}
  iex>Elixir.Roman.as_type({2001, 9, 1, 4, false})
  730739
  iex>Elixir.Roman.as_type({2001, 9, 1, 4, false}, :fixed)
  730739
  iex>Elixir.Roman.as_type({2001, 9, 1, 4, false}, :date)
  {2001, 9, 1, 4, false}

Specs

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

Compares two Roman 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.Roman.compare({2001, 9, 1, 4, false}, {2001, 9, 1, 4, false})
  :eq
  iex>Elixir.Roman.compare({2001, 9, 1, 4, false}, {2001, 12, 3, 7, false})
  :lt
  iex>Elixir.Roman.compare({2001, 12, 3, 7, false}, {2001, 9, 1, 4, false})
  :gt
Link to this function

count(cal_date, type \\ :value)

View Source

Specs

count(fixed() | roman_date(), :atom | :index | :name | :value) ::
  :atom | integer() | String.t() | number()

Returns the count field of a Roman date.

The type parameter determines the type of the returned count:

  • :atom returns the internal name of count,
  • :index returns the position of the count field within the date,
  • :name returns the common name of the count,
  • :value returns the value of the count (default).

Examples

  iex>Elixir.Roman.count(730739)
  4
  iex>Elixir.Roman.count(730739, :atom)
  :count
  iex>Elixir.Roman.count(730739, :index)
  3
  iex>Elixir.Roman.count(730739, :name)
  "Count"
  iex>Elixir.Roman.count(730739, :value)
  4

  iex>Elixir.Roman.count({2001, 9, 1, 4, false})
  4
  iex>Elixir.Roman.count({2001, 9, 1, 4, false}, :atom)
  :count
  iex>Elixir.Roman.count({2001, 9, 1, 4, false}, :index)
  3
  iex>Elixir.Roman.count({2001, 9, 1, 4, false}, :name)
  "Count"
  iex>Elixir.Roman.count({2001, 9, 1, 4, false}, :value)
  4
Link to this function

date(year, month, event, count, leap)

View Source

Specs

Returns a Roman date from its fields year, month, event, count, leap.

Example

  iex>Elixir.Roman.date(2001, 9, 1, 4, false)
  {2001, 9, 1, 4, false}
Link to this function

date_diff(cal_date1, cal_date2)

View Source

Specs

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

Returns the difference (= number of days) between two Roman dates.

The dates can be given as fixed days or Roman 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.Roman.date_diff(730739, 730839)
  100
  iex>Elixir.Roman.date_diff(730839, 730739)
  -100
  iex>Elixir.Roman.date_diff({2001, 9, 1, 4, false}, {2001, 12, 3, 7, false})
  100
  iex>Elixir.Roman.date_diff({2001, 12, 3, 7, false}, {2001, 9, 1, 4, false})
  -100
  iex>Elixir.Roman.date_diff(730739, {2001, 12, 3, 7, false})
  100
  iex>Elixir.Roman.date_diff({2001, 9, 1, 4, false}, 730839)
  100

Specs

eq(roman_date(), roman_date()) :: boolean()

Returns true if Roman date1 is equal Roman date2, otherwise false.

Examples

  iex>Elixir.Roman.eq({2001, 9, 1, 4, false}, {2001, 9, 1, 4, false})
  true
  iex>Elixir.Roman.eq({2001, 9, 1, 4, false}, {2001, 12, 3, 7, false})
  false
  iex>Elixir.Roman.eq({2001, 12, 3, 7, false}, {2001, 9, 1, 4, false})
  false
Link to this function

event(cal_date, type \\ :value)

View Source

Specs

event(fixed() | roman_date(), :atom | :index | :name | :value) ::
  :atom | integer() | String.t() | number()

Returns the event field of a Roman date.

The type parameter determines the type of the returned event:

  • :atom returns the internal name of event,
  • :index returns the position of the event field within the date,
  • :name returns the common name of the event,
  • :value returns the value of the event (default).

Examples

  iex>Elixir.Roman.event(730739)
  1
  iex>Elixir.Roman.event(730739, :atom)
  :event
  iex>Elixir.Roman.event(730739, :index)
  2
  iex>Elixir.Roman.event(730739, :name)
  "Event"
  iex>Elixir.Roman.event(730739, :value)
  1

  iex>Elixir.Roman.event({2001, 9, 1, 4, false})
  1
  iex>Elixir.Roman.event({2001, 9, 1, 4, false}, :atom)
  :event
  iex>Elixir.Roman.event({2001, 9, 1, 4, false}, :index)
  2
  iex>Elixir.Roman.event({2001, 9, 1, 4, false}, :name)
  "Event"
  iex>Elixir.Roman.event({2001, 9, 1, 4, false}, :value)
  1

Specs

field_atom(integer()) :: atom()

Returns the name of the field atom in a Roman date at field_index.

Examples

  iex>Elixir.Roman.field_atom(0)
  :year
  iex>Elixir.Roman.field_atom(1)
  :month
  iex>Elixir.Roman.field_atom(2)
  :event
  iex>Elixir.Roman.field_atom(3)
  :count
  iex>Elixir.Roman.field_atom(4)
  :leap

Specs

field_atoms() :: [atom()]

Returns a list of the field atoms (names) of a Roman date.

Example

  iex>Elixir.Roman.field_atoms()
  [:year, :month, :event, :count, :leap]

Specs

field_count() :: integer()

Returns the number of fields in a Roman date

Example

  iex>Elixir.Roman.field_count()
  5

Specs

field_index(atom()) :: integer()

Returns the index (= position) of the field_atom in a Roman date.

Examples

  iex>Elixir.Roman.field_index(:year)
  0
  iex>Elixir.Roman.field_index(:month)
  1
  iex>Elixir.Roman.field_index(:event)
  2
  iex>Elixir.Roman.field_index(:count)
  3
  iex>Elixir.Roman.field_index(:leap)
  4
Link to this function

from_date(other_date, other_calendar)

View Source

Specs

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

Converts the other_date of the other_calendar into the equivalent date of the Roman calendar.

Example

  iex>Elixir.Roman.from_date({2001, 9, 11}, Gregorian)
  {2001, 9, 1, 4, false}

Specs

from_fixed(fixed()) :: roman_date()

Converts a fixed day to a Roman date.

Example

  iex>Elixir.Roman.from_fixed(730739)
  {2001, 9, 1, 4, false}

Specs

from_jd(tuple() | number()) :: roman_date()

Converts a Julian Day into the equivalent Roman date.

The Julian Day can be given as a tuple or by a Julian day.

Examples

  iex>Elixir.Roman.from_jd({2452163.5})
  {2001, 9, 1, 4, false}
  iex>Elixir.Roman.from_jd(2452163.5)
  {2001, 9, 1, 4, false}

Specs

from_rata_die(tuple() | integer()) :: roman_date()

Converts a RataDie date into the equivalent Roman date.

The RataDie date can be given as a tuple or by a RataDie rd.

Examples

  iex>Elixir.Roman.from_rata_die({730739})
  {2001, 9, 1, 4, false}
  iex>Elixir.Roman.from_rata_die(730739)
  {2001, 9, 1, 4, false}

Specs

from_unix(tuple() | integer()) :: roman_date()

Converts a Unix date into the equivalent Roman date.

The Unix date can be given as a tuple or by Unix seconds.

Examples

  iex>Elixir.Roman.from_unix({1000166400})
  {2001, 9, 1, 4, false}
  iex>Elixir.Roman.from_unix(1000166400)
  {2001, 9, 1, 4, false}

Specs

ge(roman_date(), roman_date()) :: boolean()

Returns true if Roman date1 is greater (= later) than or equal Roman date2, otherwise false.

Examples

  iex>Elixir.Roman.ge({2001, 9, 1, 4, false}, {2001, 9, 1, 4, false})
  true
  iex>Elixir.Roman.ge({2001, 9, 1, 4, false}, {2001, 12, 3, 7, false})
  false
  iex>Elixir.Roman.ge({2001, 12, 3, 7, false}, {2001, 9, 1, 4, false})
  true

Specs

gt(roman_date(), roman_date()) :: boolean()

Returns true if Roman date1 is greater (= later) than Roman date2, otherwise false.

Examples

  iex>Elixir.Roman.gt({2001, 9, 1, 4, false}, {2001, 9, 1, 4, false})
  false
  iex>Elixir.Roman.gt({2001, 9, 1, 4, false}, {2001, 12, 3, 7, false})
  false
  iex>Elixir.Roman.gt({2001, 12, 3, 7, false}, {2001, 9, 1, 4, false})
  true

Specs

keyword() :: atom()

Returns the internal keyword of the Roman calendar.

Example

  iex>Elixir.Roman.keyword()
  :roman

Specs

le(roman_date(), roman_date()) :: boolean()

Returns true if Roman date1 is smaller (= earlier) than or equal Roman date2, otherwise false.

Examples

  iex>Elixir.Roman.le({2001, 9, 1, 4, false}, {2001, 9, 1, 4, false})
  true
  iex>Elixir.Roman.le({2001, 9, 1, 4, false}, {2001, 12, 3, 7, false})
  true
  iex>Elixir.Roman.le({2001, 12, 3, 7, false}, {2001, 9, 1, 4, false})
  false
Link to this function

leap(cal_date, type \\ :value)

View Source

Specs

leap(fixed() | roman_date(), :atom | :index | :name | :value) ::
  :atom | integer() | String.t() | number()

Returns the leap field of a Roman 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.Roman.leap(730739)
  false
  iex>Elixir.Roman.leap(730739, :atom)
  :leap
  iex>Elixir.Roman.leap(730739, :index)
  4
  iex>Elixir.Roman.leap(730739, :name)
  "Leap"
  iex>Elixir.Roman.leap(730739, :value)
  false

  iex>Elixir.Roman.leap({2001, 9, 1, 4, false})
  false
  iex>Elixir.Roman.leap({2001, 9, 1, 4, false}, :atom)
  :leap
  iex>Elixir.Roman.leap({2001, 9, 1, 4, false}, :index)
  4
  iex>Elixir.Roman.leap({2001, 9, 1, 4, false}, :name)
  "Leap"
  iex>Elixir.Roman.leap({2001, 9, 1, 4, false}, :value)
  false

Specs

lt(roman_date(), roman_date()) :: boolean()

Returns true if Roman date1 is smaller (= earlier) than Roman date2, otherwise false.

Examples

  iex>Elixir.Roman.lt({2001, 9, 1, 4, false}, {2001, 9, 1, 4, false})
  false
  iex>Elixir.Roman.lt({2001, 9, 1, 4, false}, {2001, 12, 3, 7, false})
  true
  iex>Elixir.Roman.lt({2001, 12, 3, 7, false}, {2001, 9, 1, 4, false})
  false

Specs

module() :: module()

Returns the module of the Roman calendar.

Example

  iex>Elixir.Roman.module()
  Roman
Link to this function

month(cal_date, type \\ :value)

View Source

Specs

month(fixed() | roman_date(), :atom | :index | :name | :value) ::
  :atom | integer() | String.t() | number()

Returns the month field of a Roman 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.Roman.month(730739)
  9
  iex>Elixir.Roman.month(730739, :atom)
  :month
  iex>Elixir.Roman.month(730739, :index)
  1
  iex>Elixir.Roman.month(730739, :name)
  "Month"
  iex>Elixir.Roman.month(730739, :value)
  9

  iex>Elixir.Roman.month({2001, 9, 1, 4, false})
  9
  iex>Elixir.Roman.month({2001, 9, 1, 4, false}, :atom)
  :month
  iex>Elixir.Roman.month({2001, 9, 1, 4, false}, :index)
  1
  iex>Elixir.Roman.month({2001, 9, 1, 4, false}, :name)
  "Month"
  iex>Elixir.Roman.month({2001, 9, 1, 4, false}, :value)
  9

Specs

name() :: atom()

Returns the internal name of the Roman calendar.

Example

  iex>Elixir.Roman.name()
  "Roman"

Specs

range(roman_date(), roman_date()) :: integer()

Returns the distance between two Roman dates as a range of fixed days.

Example

  iex>Elixir.Roman.range({2001, 9, 1, 4, false}, {2001, 12, 3, 7, false})
  730739..730839

Specs

start_of_day() :: :midnight | :sunset | :sunrise | :noon

Returns the start of the day in the Roman calendar.

Possible return values are:

  • :midnight,
  • :noon,
  • :sunrise,
  • :sunset,

Example

  iex>Elixir.Roman.start_of_day()
  :midnight
Link to this function

to_date(date, other_calendar)

View Source

Specs

to_date(roman_date(), module()) :: tuple()

Converts a Roman date into the equivalent date of the other_calendar.

For the following example to work the Gregorian calendar must be available.

Example

  iex>Elixir.Roman.to_date({2001, 9, 1, 4, false}, Gregorian)
  {2001, 9, 11}

Specs

to_fixed(roman_date()) :: fixed()

Converts a Roman date tuple into a fixed day.

Example

  iex>Elixir.Roman.to_fixed({2001, 9, 1, 4, false})
  730739
Link to this function

to_fixed(year, month, event, count, leap)

View Source

Specs

Converts a Roman date given by year, month, event, count, leap into a fixed day.

Example

  iex>Elixir.Roman.to_fixed(2001, 9, 1, 4, false)
  730739

Specs

to_jd(roman_date()) :: {number()}

Converts a Roman date into the equivalent Julian Day.

Example

  iex>Elixir.Roman.to_jd({2001, 9, 1, 4, false})
  {2452163.5}
Link to this function

to_jd(year, month, event, count, leap)

View Source

Specs

Converts a Roman date given by year, month, event, count, leap into the equivalent Julian Day.

Example

  iex>Elixir.Roman.to_jd(2001, 9, 1, 4, false)
  {2452163.5}

Specs

to_rata_die(roman_date()) :: {integer()}

Converts a Roman date into the equivalent RataDie date.

Example

  iex>Elixir.Roman.to_rata_die({2001, 9, 1, 4, false})
  {730739}
Link to this function

to_rata_die(year, month, event, count, leap)

View Source

Specs

to_rata_die(
  roman_year(),
  roman_month(),
  roman_event(),
  roman_count(),
  roman_leap()
) :: {integer()}

Converts a Roman date given by year, month, event, count, leap into the equivalent RataDie date.

Example

  iex>Elixir.Roman.to_rata_die(2001, 9, 1, 4, false)
  {730739}

Specs

to_unix(roman_date()) :: {integer()}

Converts a Roman date into the equivalent Unix date.

Example

  iex>Elixir.Roman.to_unix({2001, 9, 1, 4, false})
  {1000166400}
Link to this function

to_unix(year, month, event, count, leap)

View Source

Specs

Converts a Roman date given by year, month, event, count, leap into the equivalent Unix date.

Example

  iex>Elixir.Roman.to_unix(2001, 9, 1, 4, false)
  {1000166400}

Specs

today(:fixed | :date) :: fixed() | roman_date()

Returns the current date either as a fixed day or a Roman 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 Roman date.

Examples

  Elixir.Roman.today()
  730739
  Elixir.Roman.today(:fixed)
  730739
  Elixir.Roman.today(:date)
  {2001, 9, 1, 4, false}
Link to this function

year(cal_date, type \\ :value)

View Source

Specs

year(fixed() | roman_date(), :atom | :index | :name | :value) ::
  :atom | integer() | String.t() | number()

Returns the year field of a Roman 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.Roman.year(730739)
  2001
  iex>Elixir.Roman.year(730739, :atom)
  :year
  iex>Elixir.Roman.year(730739, :index)
  0
  iex>Elixir.Roman.year(730739, :name)
  "Year"
  iex>Elixir.Roman.year(730739, :value)
  2001

  iex>Elixir.Roman.year({2001, 9, 1, 4, false})
  2001
  iex>Elixir.Roman.year({2001, 9, 1, 4, false}, :atom)
  :year
  iex>Elixir.Roman.year({2001, 9, 1, 4, false}, :index)
  0
  iex>Elixir.Roman.year({2001, 9, 1, 4, false}, :name)
  "Year"
  iex>Elixir.Roman.year({2001, 9, 1, 4, false}, :value)
  2001