View Source Mobilizon.Cldr.Calendar (Mobilizon v4.1.0-alpha.1)
Data functions to retrieve localised calendar information.
Cldr
defines formats for several calendars, the names of which
are returned by Cldr.known_calendars/0
.
Currently this implementation only supports the :gregorian
,
:persian
, :coptic
and ethiopic
calendars.
The :gregorian
calendar aligns with the proleptic Gregorian calendar
defined by Elixir, Calendar.ISO
.
Summary
Functions
Return the calendar module for a locale.
Returns the calendar module preferred for a territory.
Returns a keyword list of options than can be applied to
NimbleStrftime.format/3
.
Functions
Return the calendar module for a locale.
Arguments
:locale
is 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> Mobilizon.Cldr.Calendar.calendar_from_locale "en-GB"
{:ok, Cldr.Calendar.GB}
iex> Mobilizon.Cldr.Calendar.calendar_from_locale "en-GB-u-ca-gregory"
{:ok, Cldr.Calendar.Gregorian}
iex> Mobilizon.Cldr.Calendar.calendar_from_locale "en"
{:ok, Cldr.Calendar.US}
iex> Mobilizon.Cldr.Calendar.calendar_from_locale "fa-IR"
{:ok, Cldr.Calendar.Persian}
Returns the calendar module preferred for a territory.
Arguments
territory
is any valid ISO3166-2 code as anString.t
or upcasedatom()
Returns
{:ok, calendar_module}
or{:error, {exception, reason}}
Examples
iex> Mobilizon.Cldr.Calendar.calendar_from_territory :US
{:ok, Cldr.Calendar.Gregorian}
iex> Mobilizon.Cldr.Calendar.calendar_from_territory :XX
{:error, {Cldr.UnknownTerritoryError, "The territory :XX 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
:gregorian
for a territoryThat 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
.
cyclic_years(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)
View Sourceday_periods(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)
View Sourcedays(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)
View Sourceeras(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)
View Sourcemonth_patterns(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)
View Sourcemonths(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)
View Sourcequarters(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)
View Sourcestrftime_options!(locale \\ Mobilizon.Cldr.get_locale(), options \\ [])
View SourceReturns a keyword list of options than can be applied to
NimbleStrftime.format/3
.
The hex package nimble_strftime
provides a format/3
function to format dates, times and datetimes.
It takes a set of options that can return day, month and am/pm names.
strftime_options!
returns a keyword list than can be used as these
options to return localised names for days, months and am/pm.
Arguments
locale
is any locale returned byMyApp.Cldr.known_locale_names/0
. The default isMyApp.Cldr.get_locale/0
options
is a set of keyword options. The default is[]
Options
:calendar
is the name of any known CLDR calendar. The default is:gregorian
.
Example
iex: MyApp.Cldr.Calendar.strftime_options!
[
am_pm_names: #Function<0.32021692/1 in MyApp.Cldr.Calendar.strftime_options/2>,
month_names: #Function<1.32021692/1 in MyApp.Cldr.Calendar.strftime_options/2>,
abbreviated_month_names: #Function<2.32021692/1 in MyApp.Cldr.Calendar.strftime_options/2>,
day_of_week_names: #Function<3.32021692/1 in MyApp.Cldr.Calendar.strftime_options/2>,
abbreviated_day_of_week_names: #Function<4.32021692/1 in MyApp.Cldr.Calendar.strftime_options/2>
]
Typical usage
iex: NimbleStrftime.format(Date.today(), MyApp.Cldr.Calendar.strftime_options!())