Cldr Dates & Times v1.2.0 Cldr.Date View Source
Provides an API for the 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
. Use of other calendars may not produce
the expected results.
CLDR provides standard format strings for Date
which
are reresented by the names :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
Formats a date according to a format string as defined in CLDR and described in TR35
Returns either {:ok, formatted_string}
or {:error, reason}
.
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:format:
:short
|:medium
|:long
|:full
or a format string. The default is:medium
locale:
any locale returned byCldr.known_locale_names()
. The default isCldr.get_current_locale()
number_system:
a number system into which the formatted date digits should be transliterated
Examples
iex> Cldr.Date.to_string ~D[2017-07-10], format: :medium, locale: Cldr.Locale.new!("en")
{:ok, "Jul 10, 2017"}
iex> Cldr.Date.to_string ~D[2017-07-10], locale: Cldr.Locale.new!("en")
{:ok, "Jul 10, 2017"}
iex> Cldr.Date.to_string ~D[2017-07-10], format: :full, locale: Cldr.Locale.new!("en")
{:ok, "Monday, July 10, 2017"}
iex> Cldr.Date.to_string ~D[2017-07-10], format: :short, locale: Cldr.Locale.new!("en")
{:ok, "7/10/17"}
iex> Cldr.Date.to_string ~D[2017-07-10], format: :short, locale: "fr"
{:ok, "10/07/2017"}
iex> 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
Options
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: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_current_locale/0
number_system:
a number system into which the formatted date digits should be transliterated
Returns
formatted_date
orraises an exception.
Examples
iex> Cldr.Date.to_string! ~D[2017-07-10], format: :medium, locale: Cldr.Locale.new!("en")
"Jul 10, 2017"
iex> Cldr.Date.to_string! ~D[2017-07-10], locale: Cldr.Locale.new!("en")
"Jul 10, 2017"
iex> Cldr.Date.to_string! ~D[2017-07-10], format: :full, locale: Cldr.Locale.new!("en")
"Monday, July 10, 2017"
iex> Cldr.Date.to_string! ~D[2017-07-10], format: :short, locale: Cldr.Locale.new!("en")
"7/10/17"
iex> Cldr.Date.to_string! ~D[2017-07-10], format: :short, locale: "fr"
"10/07/2017"
iex> Cldr.Date.to_string! ~D[2017-07-10], format: :long, locale: "af"
"10 Julie 2017"