View Source Jalaali.Calendar (jalaali v0.4.1)

A calendar implementation based on jalaali calendar system

Link to this section Summary

Functions

Converts the given date into a string.

Converts a Date struct to string human readable format

Calculates the day and era from the given year, month, and day.

Returns day of week on a spesific set of year, month and day

Calculates the day of the year from the given year, month, and day. It is an integer from 1 to 366.

In Jalaali calendar new day starts at midnight. This function always returns {0, 1} as result.

Returns how many months there are in the given year.

Converts the t:Calendar.iso_days format to the datetime format specified by this calendar.

Returns the t:Calendar.iso_days format of the specified date.

Converts the datetime (without time zone) into a human readable string.

Calculates the quarter of the year from the given year, month, and day. It is an integer from 1 to 4.

Converts a day fraction to this Calendar's representation of time.

Returns the normalized day fraction of the specified time.

Converts the given time into a string.

Calculates the year and era from the given year.

Link to this section Types

@type day() :: pos_integer()
@type day_fraction() ::
  {parts_in_day :: non_neg_integer(), parts_per_day :: pos_integer()}
@type day_of_week() :: pos_integer()
@type hour() :: integer()
@type iso_days() :: {days :: integer(), day_fraction()}
@type microsecond() :: integer() | {integer(), integer()}
@type minute() :: integer()
@type month() :: pos_integer()
@type second() :: integer()
@type year() :: neg_integer() | integer()

Link to this section Functions

Link to this function

date_to_string(year, month, day)

View Source
@spec date_to_string(year(), month(), day()) :: String.t()

Converts the given date into a string.

Link to this function

date_to_string(year, month, day, atom)

View Source
@spec date_to_string(year(), month(), day(), :extended | :basic) :: String.t()

Converts a Date struct to string human readable format

  • Extended type of string date. e.g.: "2017-01-05" :extended
  • Basic type of string date. e.g.: "20170105" :basic
Link to this function

datetime_to_string(year, month, day, hour, minute, second, microsecond, time_zone, zone_abbr, utc_offset, std_offset)

View Source
@spec datetime_to_string(
  integer(),
  integer(),
  integer(),
  integer(),
  integer(),
  integer(),
  {any(), integer()},
  binary(),
  any(),
  number(),
  number()
) :: String.t()

Convers the datetime (with time zone) into a human readable string.

Link to this function

day_of_era(year, month, day)

View Source
@spec day_of_era(year(), month(), day()) :: {day :: pos_integer(), era :: 0..1}

Calculates the day and era from the given year, month, and day.

examples

Examples

iex> Jalaali.Calendar.day_of_era(0, 1, 1)
{366, 0}
iex> Jalaali.Calendar.day_of_era(1, 1, 1)
{1, 1}
iex> Jalaali.Calendar.day_of_era(0, 12, 30)
{1, 0}
iex> Jalaali.Calendar.day_of_era(0, 12, 29)
{2, 0}
iex> Jalaali.Calendar.day_of_era(-1, 12, 29)
{367, 0}
Link to this function

day_of_week(year, month, day, starting_on)

View Source
@spec day_of_week(integer(), pos_integer(), pos_integer(), atom()) ::
  tuple() | {1 | 2 | 3 | 4 | 5 | 6 | 7, 1, 7}

Returns day of week on a spesific set of year, month and day

Link to this function

day_of_year(year, month, day)

View Source
@spec day_of_year(year(), month(), day()) :: 1..366

Calculates the day of the year from the given year, month, and day. It is an integer from 1 to 366.

examples

Examples

iex> Jalaali.Calendar.day_of_year(1398, 1, 31)
31
iex> Jalaali.Calendar.day_of_year(-61, 2, 1)
32
iex> Jalaali.Calendar.day_of_year(1397, 2, 28)
59
Link to this function

day_rollover_relative_to_midnight_utc()

View Source

In Jalaali calendar new day starts at midnight. This function always returns {0, 1} as result.

Link to this function

days_in_month(year, month)

View Source
@spec days_in_month(year(), month()) :: day()
@spec leap_year?(year()) :: boolean()
@spec months_in_year(year()) :: 12

Returns how many months there are in the given year.

It's always 12 for Jalaali calendar system.

examples

Examples

iex> Jalaali.Calendar.months_in_year(1398)
12
Link to this function

naive_datetime_from_iso_days(arg)

View Source
@spec naive_datetime_from_iso_days(iso_days()) ::
  {year(), month(), day(), hour(), minute(), second(), microsecond()}

Converts the t:Calendar.iso_days format to the datetime format specified by this calendar.

Link to this function

naive_datetime_to_iso_days(year, month, day, hour, minute, second, microsecond)

View Source
@spec naive_datetime_to_iso_days(
  year(),
  month(),
  day(),
  hour(),
  minute(),
  second(),
  microsecond()
) :: iso_days()

Returns the t:Calendar.iso_days format of the specified date.

Link to this function

naive_datetime_to_string(year, month, day, hour, minute, second, microsecond)

View Source
@spec naive_datetime_to_string(
  year(),
  month(),
  day(),
  hour(),
  minute(),
  second(),
  microsecond()
) ::
  String.t()

Converts the datetime (without time zone) into a human readable string.

Link to this function

quarter_of_year(year, month, day)

View Source
@spec quarter_of_year(year(), month(), day()) :: 1..4

Calculates the quarter of the year from the given year, month, and day. It is an integer from 1 to 4.

examples

Examples

iex> Jalaali.Calendar.quarter_of_year(1398, 1, 31)
1
iex> Jalaali.Calendar.quarter_of_year(123, 4, 3)
2
iex> Jalaali.Calendar.quarter_of_year(-61, 9, 31)
3
iex> Jalaali.Calendar.quarter_of_year(2678, 12, 28)
4
Link to this function

time_from_day_fraction(arg)

View Source
@spec time_from_day_fraction(day_fraction()) ::
  {hour(), minute(), second(), microsecond()}

Converts a day fraction to this Calendar's representation of time.

examples

Examples

iex> Calendar.ISO.time_from_day_fraction({1,2})
{12, 0, 0, {0, 6}}
iex> Calendar.ISO.time_from_day_fraction({13,24})
{13, 0, 0, {0, 6}}
Link to this function

time_to_day_fraction(hour, minute, second, arg)

View Source
@spec time_to_day_fraction(number(), number(), number(), {number(), any()}) ::
  {number(), 86_400_000_000}

Returns the normalized day fraction of the specified time.

examples

Examples

iex> Calendar.ISO.time_to_day_fraction(0, 0, 0, {0, 6})
{0, 86400000000}
iex> Calendar.ISO.time_to_day_fraction(12, 34, 56, {123, 6})
{45296000123, 86400000000}
Link to this function

time_to_string(hour, minute, second, microsecond)

View Source
@spec time_to_string(integer(), integer(), integer(), {any(), integer()}) :: binary()

Converts the given time into a string.

Link to this function

time_to_string(hour, minute, second, arg, format)

View Source
Link to this function

valid_date?(year, month, day)

View Source
Link to this function

valid_time?(hour, minute, second, arg)

View Source
@spec year_of_era(year()) :: {year(), era :: 0..1}

Calculates the year and era from the given year.

The Jalaali calendar has two eras: the current era which starts in year 1 and is defined as era 1. and a second era for those years less than 1 defined as era 0.

examples

Examples

iex> Jalaali.Calendar.year_of_era(1)
{1, 1}
iex> Jalaali.Calendar.year_of_era(1398)
{1398, 1}
iex> Jalaali.Calendar.year_of_era(0)
{1, 0}
iex> Jalaali.Calendar.year_of_era(-1)
{2, 0}