Cldr.Date (Cldr Dates & Times v2.6.0) View Source
Provides localization and formatting of a Date
struct or any map with the keys :year, :month,
:day and :calendar.
Cldr.Date provides support for the built-in calendar
Calendar.ISO or any calendars defined with
ex_cldr_calendars
CLDR provides standard format strings for Date which
are reresented by the styles :short, :medium, :long
and :full. This allows for locale-independent
formatting since each locale may define the underlying
format string as appropriate.
Link to this section Summary
Link to this section Functions
to_string(date, backend \\ Cldr.Date.default_backend(), options \\ [])
View SourceSpecs
to_string(map(), Cldr.backend() | Keyword.t(), Keyword.t()) :: {:ok, String.t()} | {:error, {module(), String.t()}}
Formats a date according to a format string as defined in CLDR and described in TR35
Arguments
dateis a%Date{}struct or any map that contains the keysyear,month,dayandcalendarbackendis any module that includesuse Cldrand therefore is aCldrbackend module. The default isCldr.default_backend/0.optionsis a keyword list of options for formatting. The valid options are:
Options
format::short|:medium|:long|:fullor a format string. The default is:mediumlocale:any locale returned byCldr.known_locale_names/1. The default isCldr.get_locale().number_system:a number system into which the formatted date digits should be transliterated
Returns
{:ok, formatted_string}or{:error, reason}
Examples
iex> Cldr.Date.to_string ~D[2017-07-10], MyApp.Cldr, format: :medium, locale: "en"
{:ok, "Jul 10, 2017"}
iex> Cldr.Date.to_string ~D[2017-07-10], MyApp.Cldr, locale: "en"
{:ok, "Jul 10, 2017"}
iex> Cldr.Date.to_string ~D[2017-07-10], MyApp.Cldr, format: :full, locale: "en"
{:ok, "Monday, July 10, 2017"}
iex> Cldr.Date.to_string ~D[2017-07-10], MyApp.Cldr, format: :short, locale: "en"
{:ok, "7/10/17"}
iex> Cldr.Date.to_string ~D[2017-07-10], MyApp.Cldr, format: :short, locale: "fr"
{:ok, "10/07/2017"}
iex> Cldr.Date.to_string ~D[2017-07-10], MyApp.Cldr, style: :long, locale: "af"
{:ok, "10 Julie 2017"}
to_string!(date, backend \\ Cldr.Date.default_backend(), options \\ [])
View SourceSpecs
Formats a date according to a format string as defined in CLDR and described in TR35
Arguments
dateis a%Date{}struct or any map that contains the keysyear,month,dayandcalendarbackendis any module that includesuse Cldrand therefore is aCldrbackend module. The default isCldr.default_backend/0.optionsis a keyword list of options for formatting.
Options
format::short|:medium|:long|:fullor a format string. The default is:mediumlocaleis any valid locale name returned byCldr.known_locale_names/0or aCldr.LanguageTagstruct. The default isCldr.get_locale/0number_system:a number system into which the formatted date digits should be transliterated
Returns
formatted_dateorraises an exception.
Examples
iex> Cldr.Date.to_string! ~D[2017-07-10], MyApp.Cldr, format: :medium, locale: "en"
"Jul 10, 2017"
iex> Cldr.Date.to_string! ~D[2017-07-10], MyApp.Cldr, locale: "en"
"Jul 10, 2017"
iex> Cldr.Date.to_string! ~D[2017-07-10], MyApp.Cldr, format: :full,locale: "en"
"Monday, July 10, 2017"
iex> Cldr.Date.to_string! ~D[2017-07-10], MyApp.Cldr, format: :short, locale: "en"
"7/10/17"
iex> Cldr.Date.to_string! ~D[2017-07-10], MyApp.Cldr, format: :short, locale: "fr"
"10/07/2017"
iex> Cldr.Date.to_string! ~D[2017-07-10], MyApp.Cldr, format: :long, locale: "af"
"10 Julie 2017"