Elixir v1.5.3 Calendar.ISO View Source

A calendar implementation that follows to ISO8601.

This calendar implements the proleptic Gregorian calendar and is therefore compatible with the calendar used in most countries today. The proleptic means the Gregorian rules for leap years are applied for all time, consequently the dates give different results before the year 1583 from when the Gregorian calendar was adopted.

Note that while ISO8601 allows times and datetimes to specify 24:00:00 as the zero hour of the next day, this notation is not supported by Elixir.

Link to this section Summary

Functions

Converts the given date into a string

Calculates the day of the week from the given year, month, and day

Define the rollover moment for the given calendar

Returns how many days there are in the given year-month

Returns if the given year is a leap 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 string

Converts a day fraction to this Calendar’s representation of time

Returns the normalized day fraction of the specified time

Should return true if the given date describes a proper date in the calendar

Should return true if the given time describes a proper time in the calendar

Link to this section Types

Link to this type month() View Source
month() :: 1..12
Link to this type year() View Source
year() :: 0..9999

Link to this section Functions

Link to this function date_to_string(year, month, day) View Source

Converts the given date into a string.

Link to this function datetime_to_string(year, month, day, hour, minute, second, microsecond, time_zone, zone_abbr, utc_offset, std_offset) View Source

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

Link to this function day_of_week(year, month, day) View Source
day_of_week(year(), month(), day()) :: 1..7

Calculates the day of the week from the given year, month, and day.

It is an integer from 1 to 7, where 1 is Monday and 7 is Sunday.

Examples

iex> Calendar.ISO.day_of_week(2016, 10, 31)
1
iex> Calendar.ISO.day_of_week(2016, 11, 01)
2
iex> Calendar.ISO.day_of_week(2016, 11, 02)
3
iex> Calendar.ISO.day_of_week(2016, 11, 03)
4
iex> Calendar.ISO.day_of_week(2016, 11, 04)
5
iex> Calendar.ISO.day_of_week(2016, 11, 05)
6
iex> Calendar.ISO.day_of_week(2016, 11, 06)
7
Link to this function day_rollover_relative_to_midnight_utc() View Source

Define the rollover moment for the given calendar.

This is the moment, in your calendar, when the current day ends and the next day starts.

The result of this function is used to check if two calendars rollover at the same time of day. If they do not, we can only convert datetimes and times between them. If they do, this means that we can also convert dates as well as naive datetimes between them.

This day fraction should be in its most simplified form possible, to make comparisons fast.

Examples

  • If, in your Calendar, a new day starts at midnight, return {0, 1}.
  • If, in your Calendar, a new day starts at sunrise, return {1, 4}.
  • If, in your Calendar, a new day starts at noon, return {1, 2}.
  • If, in your Calendar, a new day starts at sunset, return {3, 4}.

Callback implementation for Calendar.day_rollover_relative_to_midnight_utc/0.

Link to this function days_in_month(year, month) View Source
days_in_month(year(), month()) :: 28..31

Returns how many days there are in the given year-month.

Examples

iex> Calendar.ISO.days_in_month(1900, 1)
31
iex> Calendar.ISO.days_in_month(1900, 2)
28
iex> Calendar.ISO.days_in_month(2000, 2)
29
iex> Calendar.ISO.days_in_month(2001, 2)
28
iex> Calendar.ISO.days_in_month(2004, 2)
29
iex> Calendar.ISO.days_in_month(2004, 4)
30
Link to this function leap_year?(year) View Source
leap_year?(year()) :: boolean()

Returns if the given year is a leap year.

Examples

iex> Calendar.ISO.leap_year?(2000)
true
iex> Calendar.ISO.leap_year?(2001)
false
iex> Calendar.ISO.leap_year?(2004)
true
iex> Calendar.ISO.leap_year?(1900)
false

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

Examples

iex> Calendar.ISO.naive_datetime_from_iso_days({0, {0, 86400}})
{0, 1, 1, 0, 0, 0, {0, 6}}
iex> Calendar.ISO.naive_datetime_from_iso_days({730485, {0, 86400}})
{2000, 1, 1, 0, 0, 0, {0, 6}}
iex> Calendar.ISO.naive_datetime_from_iso_days({730485, {43200, 86400}})
{2000, 1, 1, 12, 0, 0, {0, 6}}
Link to this function naive_datetime_to_iso_days(year, month, day, hour, minute, second, microsecond) View Source

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

Examples

iex> Calendar.ISO.naive_datetime_to_iso_days(0, 1, 1, 0, 0, 0, {0, 6})
{0, {0, 86400000000}}
iex> Calendar.ISO.naive_datetime_to_iso_days(2000, 1, 1, 12, 0, 0, {0, 6})
{730485, {43200000000, 86400000000}}
iex> Calendar.ISO.naive_datetime_to_iso_days(2000, 1, 1, 13, 0, 0, {0, 6})
{730485, {46800000000, 86400000000}}
Link to this function naive_datetime_to_string(year, month, day, hour, minute, second, microsecond) View Source

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

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

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

Returns the normalized day fraction of the specified time.

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, format \\ :extended) View Source

Converts the given time into a string.

Link to this function valid_date?(year, month, day) View Source

Should return true if the given date describes a proper date in the calendar.

Callback implementation for Calendar.valid_date?/3.

Link to this function valid_time?(hour, minute, second, arg) View Source

Should return true if the given time describes a proper time in the calendar.

Callback implementation for Calendar.valid_time?/4.