Cldr Dates & Times v1.2.0 Cldr.Calendar View Source
Calendar support functions for formatting dates, times and datetimes.
Cldr
defines formats for several calendars, the names of which
are returned by Cldr.Calendar.known_calendars/0
.
Currently this implementation only supports the :gregorian
calendar which aligns with the proleptic Gregorian calendar
defined by Elixir, Calendar.ISO
.
This module will be extacted in the future to become part of a separate calendrical module.
Link to this section Summary
Functions
Returns the date n
days after the provided
data
Returns the calendar type and calendar era definitions for the calendars in CLDR
Returns a date struct for a given iso days
Returns the day of the week for a date where
the first day is Monday and the result is in
the range 1
(for Monday) to 7
(for Sunday)
Returns the ordinal day of the year for a given date
Returns the default CLDR calendar name
Returns the era number for a given rata die
Returns the era number for a given date and calendar
Returns the first day of the month
Returns the first day of a week for a locale as an ordinal number in then range one to seven with one representing Monday and seven representing Sunday
Returns iso days for a given date
Converts a datetime to iso days
Returns the minimum days required in a week for it to be considered week one of a year
Converts a date to a naive datetime
Returns the date of the next day to the provided date
Returns the date that is the first day of the n
th week of
the year that containts the supplied date
Returns the date of the previous day to the provided date
Returns the date n
days after the provided
data
Returns the CLDR data that defines the structure of a week in different locales
Returns a Date.Rage
with the first date as the
first day of the year and the last day as the last
day of the year
Link to this section Functions
Returns the calendar type and calendar era definitions for the calendars in CLDR.
Example
Cldr.Calendar.calendars
%{buddhist: %{calendar_system: "solar", eras: [{0, %{start: -198326}}]},
chinese: %{calendar_system: "lunisolar", eras: [{0, %{start: -963144}}]},
coptic: %{calendar_system: "other",
eras: [{0, %{end: 103604}}, {1, %{start: 103605}}]},
dangi: %{calendar_system: "lunisolar", eras: [{0, %{start: -852110}}]},
ethiopic: %{calendar_system: "other",
eras: [{0, %{end: 2797}}, {1, %{start: 2798}}]},
ethiopic_amete_alem: %{eras: [{0, %{end: -2006036}}]},
gregorian: %{calendar_system: "solar",
eras: [{0, %{end: 0}}, {1, %{start: 1}}]}, ...
Returns a date struct for a given iso days
Returns the day of the week for a date where
the first day is Monday and the result is in
the range 1
(for Monday) to 7
(for Sunday)
date
is aDate
or any other struct that contains the keys:year
,:month
,;day
and:calendar
Examples
iex> Cldr.Calendar.day_of_week ~D[2017-09-03]
7
iex> Cldr.Calendar.day_of_week ~D[2017-09-01]
5
Returns the ordinal day of the year for a given date.
date
is aDate
or any other struct that contains the keys:year
,:month
,;day
and:calendar
Example
iex> Cldr.Calendar.day_of_year ~D[2017-01-01]
1
iex> Cldr.Calendar.day_of_year ~D[2017-09-03]
246
iex> Cldr.Calendar.day_of_year ~D[2017-12-31]
365
Returns the default CLDR calendar name.
Note this is not the same as the default calendar
Calendar.ISO
supported by Elixir.
Example
iex> Cldr.Calendar.default_calendar
:gregorian
Returns the era number for a given rata die.
The era number is an index into Cldr list of
eras for a given calendar which is primarily
for the use of Cldr.Date.to_string/2
when
processing the format symbol G
. For further
information see Cldr.DateTime.Formatter.era/4
.
Returns the era number for a given date and calendar
date
is aDate
or any struct with the fields:year
,:month
,:day
and:calendar
calendar
is any calendar returned byCldr.Calendar.known_calendars/0
Example
iex> Cldr.Calendar.era_number_from_date ~D[2017-09-03], :gregorian
1
iex> Cldr.Calendar.era_number_from_date ~D[0000-09-03], :gregorian
0
iex> Cldr.Calendar.era_number_from_date ~D[1700-09-03], :japanese
208
Returns the first day of the month.
Note that whilst this is trivial for an ISO/Gregorian calendar it may well be quite different for other types of calendars
Returns the first day of a week for a locale as an ordinal number in then range one to seven with one representing Monday and seven representing Sunday.
locale
is any valid locale name returned byCldr.known_locale_names/0
or aCldr.LanguageTag
struct returned byCldr.Locale.new!/1
Example
iex> Cldr.Calendar.first_day_of_week "en"
7
iex> Cldr.Calendar.first_day_of_week "en-GB"
1
Returns iso days for a given date
Converts a datetime to iso days
Returns the minimum days required in a week for it to be considered week one of a year.
territory
is any territory code returned byCldr.known_territories/0
Examples
iex> Cldr.Calendar.minumim_days_in_week_one :US
1
iex> Cldr.Calendar.minumim_days_in_week_one :FR
4
Converts a date to a naive datetime
Returns the date of the next day to the provided date.
Examples
iex> Cldr.Calendar.next_day %{calendar: Calendar.ISO, day: 2, month: 1, year: 2017}
%{calendar: Calendar.ISO, day: 3, month: 1, year: 2017}
iex> Cldr.Calendar.next_day %{calendar: Calendar.ISO, day: 28, month: 2, year: 2017}
%{calendar: Calendar.ISO, day: 1, month: 3, year: 2017}
iex> Cldr.Calendar.next_day %{calendar: Calendar.ISO, day: 28, month: 2, year: 2016}
%{calendar: Calendar.ISO, day: 29, month: 2, year: 2016}
Returns the date that is the first day of the n
th week of
the year that containts the supplied date
.
date
is aDate
or any other struct that contains the keys:year
,:month
,;day
and:calendar
n
is the week number
NOTE The first week is defined according to the week definition of the ISO Week calendar.
Example
iex> Cldr.Calendar.nth_week_of_year ~D[2017-01-04], 1
%{calendar: Calendar.ISO, day: 2, month: 1, year: 2017}
Returns the date of the previous day to the provided date.
Example
iex> Cldr.Calendar.previous_day %{calendar: Calendar.ISO, day: 2, month: 1, year: 2017}
%{calendar: Calendar.ISO, day: 1, month: 1, year: 2017}
iex> Cldr.Calendar.previous_day %{calendar: Calendar.ISO, day: 1, month: 3, year: 2017}
%{calendar: Calendar.ISO, day: 28, month: 2, year: 2017}
iex> Cldr.Calendar.previous_day %{calendar: Calendar.ISO, day: 1, month: 3, year: 2016}
%{calendar: Calendar.ISO, day: 29, month: 2, year: 2016}
Returns the date n
days after the provided
data.
Example
iex> Cldr.Calendar.add %{calendar: Calendar.ISO, day: 1, month: 3, year: 2017}, 3
%{calendar: Calendar.ISO, day: 4, month: 3, year: 2017}
Returns the CLDR data that defines the structure of a week in different locales.
Example
Cldr.Calendar.week_info
%{first_day: %{IN: "sun", SM: "mon", MN: "mon", MZ: "sun", CR: "mon", AT: "mon",
LA: "sun", EE: "mon", NL: "mon", PT: "mon", PH: "sun", BG: "mon", LT: "mon",
ES: "mon", OM: "sat", SY: "sat", US: "sun", EC: "mon", SG: "sun", DM: "sun",
AR: "sun", MK: "mon", YE: "sun", KW: "sat", GB: "mon",
"GB-alt-variant": "sun", AD: "mon", UZ: "mon", KG: "mon", CZ: "mon",
FI: "mon", RO: "mon", TR: "mon", AI: "mon", MM: "sun", AS: "sun", BS: "sun",
IT: "mon", MX: "sun", BR: "sun", ID: "sun", NZ: "sun", GP: "mon", BE: "mon",
CO: "sun", GR: "mon", NP: "sun", ME: "mon", MO: "sun", ...},
min_days: %{SM: 4, SJ: 4, AT: 4, EE: 4, NL: 4, PT: 4, BG: 4, LT: 4, ES: 4,
US: 1, GI: 4, GB: 4, AD: 4, CZ: 4, FI: 4, IT: 4, GP: 4, JE: 4, BE: 4, GR: 4,
"001": 1, VI: 1, RE: 4, SE: 4, GU: 1, IS: 4, AN: 4, IM: 4, GG: 4, CH: 4,
FO: 4, UM: 1, SK: 4, AX: 4, LU: 4, FR: 4, IE: 4, HU: 4, FJ: 4, MC: 4, GF: 4,
NO: 4, DK: 4, DE: 4, LI: 4, PL: 4, VA: 4, MQ: 4}, weekend_end: nil,
weekend_start: nil}