Cldr_Dates_Times v0.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}.
dateis a%Date{}struct or any map that contains the keysyear,month,dayandcalendaroptionsis a keyword list of options for formatting. The valid options are:format::short|:medium|:long|:fullor a format string. The default is:mediumlocale:any locale returned byCldr.known_locales(). 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
Returns either the formatted_date or raises an exception.
dateis a%Date{}struct or any map that contains the keysyear,month,dayandcalendaroptionsis a keyword list of options for formatting. The valid options are:format::short|:medium|:long|:fullor a format string. The default is:mediumlocale:any locale returned byCldr.known_locales(). 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")
"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"