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

Link to this function

calendar_from_locale(locale)

View Source

Return the calendar module for a locale.

Arguments

  • :locale is any locale or locale name validated by Cldr.validate_locale/2. The default is Cldr.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}
Link to this function

calendar_from_territory(territory)

View Source

Returns the calendar module preferred for a territory.

Arguments

  • territory is any valid ISO3166-2 code as an String.t or upcased atom()

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:

  1. That another calendar is preferred over :gregorian for a territory

  2. 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.

Link to this function

cyclic_years(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)

View Source
Link to this function

day_periods(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)

View Source
Link to this function

days(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)

View Source
Link to this function

eras(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)

View Source
Link to this function

month_patterns(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)

View Source
Link to this function

months(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)

View Source
Link to this function

quarters(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ :gregorian)

View Source
Link to this function

strftime_options!(locale \\ Mobilizon.Cldr.get_locale(), options \\ [])

View Source

Returns 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 by MyApp.Cldr.known_locale_names/0. The default is MyApp.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!())