View Source Mobilizon.Cldr.Date (Mobilizon v5.0.0-beta.1)
Summary
Functions
Formats a date according to a format string as defined in CLDR and described in TR35
Arguments
date
is a%Date{}
struct or any map that contains the keysyear
,month
,day
andcalendar
options
is a keyword list of options for formatting. The valid options are:
Options
format:
:short
|:medium
|:long
|:full
or a format string. The default is:medium
.locale:
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> Mobilizon.Cldr.Date.to_string ~D[2017-07-10], format: :medium, locale: "en"
{:ok, "Jul 10, 2017"}
iex> Mobilizon.Cldr.Date.to_string ~D[2017-07-10], locale: "en"
{:ok, "Jul 10, 2017"}
iex> Mobilizon.Cldr.Date.to_string ~D[2017-07-10], format: :full, locale: "en"
{:ok, "Monday, July 10, 2017"}
iex> Mobilizon.Cldr.Date.to_string ~D[2017-07-10], format: :short, locale: "en"
{:ok, "7/10/17"}
iex> Mobilizon.Cldr.Date.to_string ~D[2017-07-10], format: :short, locale: "fr"
{:ok, "10/07/2017"}
iex> Mobilizon.Cldr.Date.to_string ~D[2017-07-10], format: :long, locale: "af"
{:ok, "10 Julie 2017"}
Formats a date according to a format string as defined in CLDR and described in TR35.
Arguments
date
is a%Date{}
struct or any map that contains the keysyear
,month
,day
andcalendar
.options
is a keyword list of options for formatting.
Options
format:
:short
|:medium
|:long
|:full
or a format string. The default is:medium
.locale
is any valid locale name returned byCldr.known_locale_names/0
or aCldr.LanguageTag
struct. The default isCldr.get_locale/0
.number_system:
a number system into which the formatted date digits should be transliterated.
Returns
formatted_date
orraises an exception.
Examples
iex> Mobilizon.Cldr.Date.to_string! ~D[2017-07-10], format: :medium, locale: "en"
"Jul 10, 2017"
iex> Mobilizon.Cldr.Date.to_string! ~D[2017-07-10], locale: "en"
"Jul 10, 2017"
iex> Mobilizon.Cldr.Date.to_string! ~D[2017-07-10], format: :full,locale: "en"
"Monday, July 10, 2017"
iex> Mobilizon.Cldr.Date.to_string! ~D[2017-07-10], format: :short, locale: "en"
"7/10/17"
iex> Mobilizon.Cldr.Date.to_string! ~D[2017-07-10], format: :short, locale: "fr"
"10/07/2017"
iex> Mobilizon.Cldr.Date.to_string! ~D[2017-07-10], format: :long, locale: "af"
"10 Julie 2017"