Cldr.DateTime.Format (Cldr Dates & Times v2.10.2) View Source

Manages the Date, Time and DateTime formats defined by CLDR.

The functions in Cldr.DateTime.Format are primarily concerned with encapsulating the data from CLDR in functions that are used during the formatting process.

Link to this section Summary

Functions

Returns a list of calendars defined for a given locale.

Returns a list of the date_time format types that are available in all locales.

Returns the GMT offset format list for a for a timezone offset for a given locale.

Returns the GMT format string for a for a timezone with an offset of zero for a given locale.

Returns the postive and negative hour format for a timezone offset for a given locale.

Link to this section Types

Specs

formats() :: Cldr.Calendar.calendar()

Specs

standard_formats() :: %{
  full: String.t(),
  long: String.t(),
  medium: String.t(),
  short: String.t()
}

Link to this section Functions

Link to this function

calendars_for(locale, backend \\ Cldr.Date.default_backend())

View Source

Specs

calendars_for(Cldr.Locale.locale_name() | Cldr.LanguageTag.t(), Cldr.backend()) ::
  {:ok, [Cldr.Calendar.calendar(), ...]} | {:error, {atom(), String.T}}

Returns a list of calendars defined for a given locale.

Arguments

Example

iex> Cldr.DateTime.Format.calendars_for "en", MyApp.Cldr
{:ok, [:buddhist, :chinese, :coptic, :dangi, :ethiopic, :ethiopic_amete_alem,
 :generic, :gregorian, :hebrew, :indian, :islamic, :islamic_civil,
 :islamic_rgsa, :islamic_tbla, :islamic_umalqura, :japanese, :persian, :roc]}
Link to this function

common_date_time_format_names(backend \\ Cldr.Date.default_backend())

View Source

Returns a list of the date_time format types that are available in all locales.

The format types returned by common_date_time_format_names are guaranteed to be available in all known locales,

Example:

iex> Cldr.DateTime.Format.common_date_time_format_names
[:bh, :bhm, :bhms, :d, :e, :e_bhm, :e_bhms, :e_hm, :e_hms, :ed, :ehm,
:ehms, :gy, :gy_md, :gy_mm_md, :gy_mmm, :gy_mmm_ed, :h, :hm, :hms, :hmsv,
:hmv, :m, :m_ed, :md, :mm_md, :mmm, :mmm_ed, :mmm_md,
:mmmmw, :ms, :y, :y_m, :y_m_ed, :y_md, :y_mm_md, :y_mmm,
:y_mmm_ed, :y_mmmm, :y_qqq, :y_qqqq, :yw]
Link to this function

date_formats( locale \\ Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar(), backend \\ Cldr.Date.default_backend() )

View Source

Specs

Returns a map of the standard date formats for a given locale and calendar.

Arguments

Examples:

iex> Cldr.DateTime.Format.date_formats "en", :gregorian, MyApp.Cldr
{:ok, %Cldr.Date.Styles{
  full: "EEEE, MMMM d, y",
  long: "MMMM d, y",
  medium: "MMM d, y",
  short: "M/d/yy"
}}

iex> Cldr.DateTime.Format.date_formats "en", :buddhist, MyApp.Cldr
{:ok, %Cldr.Date.Styles{
  full: "EEEE, MMMM d, y G",
  long: "MMMM d, y G",
  medium: "MMM d, y G",
  short: "M/d/y GGGGG"
}}
Link to this function

date_time_available_formats( locale \\ Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar(), backend \\ Cldr.Date.default_backend() )

View Source

Specs

date_time_available_formats(
  Cldr.Locale.locale_name() | Cldr.LanguageTag.t(),
  Cldr.Calendar.calendar(),
  Cldr.backend()
) :: {:ok, map()} | {:error, {atom(), String.t()}}

Returns a map of the available non-standard datetime formats for a given locale and calendar.

Arguments

Examples:

iex> Cldr.DateTime.Format.date_time_available_formats "en"
{:ok,
 %{
   d: "d",
   mmm_ed: "E, MMM d",
   ehm: "E h:mm a",
   gy_mmm: "MMM y G",
   y_mmmm: "MMMM y",
   y: "y",
   y_m_ed: "E, M/d/y",
   md: "M/d",
   e_hm: "E HH:mm",
   bh: "h B",
   gy_mmm_ed: "E, MMM d, y G",
   gy_mm_md: "MMM d, y G",
   e: "ccc",
   ehms: "E h:mm:ss a",
   y_mm_md: "MMM d, y",
   y_qqqq: "QQQQ y",
   h: "HH",
   bhms: "h:mm:ss B",
   y_md: "M/d/y",
   y_qqq: "QQQ y",
   mmm_md: "MMMM d",
   y_mmm: "MMM y",
   y_mmm_ed: "E, MMM d, y",
   e_bhm: "E h:mm B",
   ms: "mm:ss",
   mmm: "LLL",
   bhm: "h:mm B",
   mm_md: "MMM d",
   hms: "h:mm:ss a",
   e_hms: "E HH:mm:ss",
   hmv: "h:mm a v",
   gy: "y G",
   m: "L",
   y_m: "M/y",
   m_ed: "E, M/d",
   hmsv: "h:mm:ss a v",
   hm: "h:mm a",
   e_bhms: "E h:mm:ss B",
   ed: "d E",
   gy_md: "M/d/y GGGGG",
   mmmmw: %{one: "'week' W 'of' MMMM", other: "'week' W 'of' MMMM"},
   yw: %{one: "'week' w 'of' Y", other: "'week' w 'of' Y"}
 }}
Link to this function

date_time_formats( locale \\ Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar(), backend \\ Cldr.Date.default_backend() )

View Source

Specs

date_time_formats(
  Cldr.Locale.locale_name() | Cldr.LanguageTag.t(),
  Cldr.Calendar.calendar(),
  Cldr.backend()
) :: {:ok, map()} | {:error, {atom(), String.t()}}

Returns a map of the standard datetime formats for a given locale and calendar.

Arguments

Examples:

iex> Cldr.DateTime.Format.date_time_formats "en"
{:ok, %Cldr.DateTime.Styles{
  full: "{1} 'at' {0}",
  long: "{1} 'at' {0}",
  medium: "{1}, {0}",
  short: "{1}, {0}"
}}

iex> Cldr.DateTime.Format.date_time_formats "en", :buddhist, MyApp.Cldr
{:ok, %Cldr.DateTime.Styles{
  full: "{1} 'at' {0}",
  long: "{1} 'at' {0}",
  medium: "{1}, {0}",
  short: "{1}, {0}"
}}
Link to this function

gmt_format(locale, backend \\ Cldr.Date.default_backend())

View Source

Specs

Returns the GMT offset format list for a for a timezone offset for a given locale.

Arguments

Example

iex> Cldr.DateTime.Format.gmt_format "en", MyApp.Cldr
{:ok, ["GMT", 0]}
Link to this function

gmt_format_type(list, format_type)

View Source
Link to this function

gmt_zero_format(locale, backend \\ Cldr.Date.default_backend())

View Source

Specs

gmt_zero_format(
  Cldr.Locale.locale_name() | Cldr.LanguageTag.t(),
  Cldr.backend()
) ::
  {:ok, String.t()} | {:error, {atom(), String.t()}}

Returns the GMT format string for a for a timezone with an offset of zero for a given locale.

Arguments

Example

iex> Cldr.DateTime.Format.gmt_zero_format "en", MyApp.Cldr
{:ok, "GMT"}
Link to this function

hour_format(locale \\ Cldr.get_locale(), backend \\ Cldr.Date.default_backend())

View Source

Specs

hour_format(Cldr.Locale.locale_name() | Cldr.LanguageTag.t(), Cldr.backend()) ::
  {:ok, {String.t(), String.t()}} | {:error, {atom(), String.t()}}

Returns the postive and negative hour format for a timezone offset for a given locale.

Arguments

Example

iex> Cldr.DateTime.Format.hour_format "en", MyApp.Cldr
{:ok, {"+HH:mm", "-HH:mm"}}
Link to this function

interval_formats( locale \\ Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar(), backend \\ Cldr.Date.default_backend() )

View Source

Specs

interval_formats(
  Cldr.Locale.locale_name() | Cldr.LanguageTag.t(),
  Cldr.Calendar.calendar(),
  Cldr.backend()
) :: {:ok, map()} | {:error, {atom(), String.t()}}

Returns a map of the interval formats for a given locale and calendar.

Arguments

Examples:

Cldr.DateTime.Format.interval_formats "en", :gregorian, MyApp.Cldr
=> {:ok,
 %{
   bh: %{b: ["h B", "h B"], h: ["h", "h B"]},
   bhm: %{b: ["h:mm B", "h:mm B"], h: ["h:mm", "h:mm B"], m: ["h:mm", "h:mm B"]},
   d: %{d: ["d", "d"]},
   gy: %{g: ["y G", "y G"], y: ["y", "y G"]},
   ...
Link to this function

time_formats( locale \\ Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar(), backend \\ Cldr.Date.default_backend() )

View Source

Specs

time_formats(
  Cldr.Locale.locale_name() | Cldr.LanguageTag,
  Cldr.Calendar.calendar(),
  Cldr.backend()
) :: {:ok, standard_formats()} | {:error, {atom(), String.t()}}

Returns a map of the standard time formats for a given locale and calendar.

Arguments

Examples:

iex> Cldr.DateTime.Format.time_formats "en"
{:ok, %Cldr.Time.Styles{
  full: "h:mm:ss a zzzz",
  long: "h:mm:ss a z",
  medium: "h:mm:ss a",
  short: "h:mm a"
}}

iex> Cldr.DateTime.Format.time_formats "en", :buddhist
{:ok, %Cldr.Time.Styles{
  full: "h:mm:ss a zzzz",
  long: "h:mm:ss a z",
  medium: "h:mm:ss a",
  short: "h:mm a"
}}