Cldr.Calendar.Preference (Cldr Calendars v2.3.0)
View SourceSummary
Functions
Return the calendar module for a locale.
Returns the calendar module preferred for a territory.
Functions
Return the calendar module for a locale.
Arguments
:localeis any locale or locale name validated byCldr.validate_locale/2. The default isCldr.get_locale()which returns the locale set for the current process.
Returns
{:ok, calendar_module}or{:error, {exception, reason}}
Examples
iex> Cldr.Calendar.Preference.calendar_from_locale(:"en-GB")
{:ok, Cldr.Calendar.GB}
iex> Cldr.Calendar.Preference.calendar_from_locale("en-GB-u-ca-gregory")
{:ok, Cldr.Calendar.Gregorian}
iex> Cldr.Calendar.Preference.calendar_from_locale(:en)
{:ok, Cldr.Calendar.US}
iex> Cldr.Calendar.Preference.calendar_from_locale("en-u-ca-iso8601")
{:ok, Cldr.Calendar.ISOWeek}
iex> Cldr.Calendar.Preference.calendar_from_locale("en-u-fw-mon")
{:ok, Cldr.Calendar.Gregorian}
iex> Cldr.Calendar.Preference.calendar_from_locale(:"fa-IR")
{:ok, Cldr.Calendar.Persian}
iex> Cldr.Calendar.Preference.calendar_from_locale("fa-IR-u-ca-gregory")
{:ok, Cldr.Calendar.Gregorian}
Returns the calendar module preferred for a territory.
Arguments
territoryis any valid ISO3166-2 code as anString.t/0or upcasedt.atom/0.
Returns
{:ok, calendar_module}or{:error, {exception, reason}}
Examples
iex> Cldr.Calendar.Preference.calendar_from_territory :US
{:ok, Cldr.Calendar.US}
iex> Cldr.Calendar.Preference.calendar_from_territory :YY
{:error, {Cldr.UnknownTerritoryError, "The territory :YY is unknown"}}Notes
The overwhelming majority of territories have
:gregorian as their first preferred calendar
and therefore Cldr.Calendar.Gregorian
will be returned for most territories.
Returning any other calendar module would require:
That another calendar is preferred over
:gregorianfor a territory.That a calendar module is available to support that calendar.
As an example, Iran (territory :IR) prefers the
:persian calendar. If the optional library
ex_cldr_calendars_persian
is installed, the calendar module Cldr.Calendar.Persian will
be returned. If it is not installed, Cldr.Calendar.Gregorian
will be returned as :gregorian is the second preference
for :IR.