plotex v0.2.1 Plotex.Cldr.DateTime.Format

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 map of the standard date formats for a given locale and calendar.

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

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

Returns the time period for a given time of day.

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.

Returns a boolean indicating is a given language defines the notion of "noon" and "midnight"

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

Link to this section Types

Link to this type

calendar()

calendar() :: atom()
Link to this type

formats()

formats() :: map()

Link to this section Functions

Link to this function

calendars_for(locale \\ Plotex.Cldr.get_locale())

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

Returns a list of calendars defined for a given locale.

Arguments

Example

iex> Elixir.Plotex.Cldr.DateTime.Format.calendars_for "en"
{: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

date_formats(locale \\ Plotex.Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar())

date_formats(Cldr.Locale.locale_name() | Cldr.LanguageTag.t(), calendar()) ::
  {:ok, map()} | {:error, {module(), String.t()}}

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

Arguments

Examples:

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

iex> Elixir.Plotex.Cldr.DateTime.Format.date_formats "en", :buddhist
{:ok, %Cldr.Date.Formats{
  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 \\ Plotex.Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar())

date_time_available_formats(
  Cldr.Locale.locale_name() | Cldr.LanguageTag.t(),
  calendar()
) :: {:ok, formats()}

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

Arguments

Examples:

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

date_time_formats(locale \\ Plotex.Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar())

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

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

Arguments

Examples:

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

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

day_period_for(time, language)

Returns the time period for a given time of day.

Arguments

  • time is any Time.t or a map with at least :hour, :minute and :second keys

  • language is a binary representation of a valid and configured language in Cldr

The time period is a locale-specific key that is used to localise a time into a textual representation of "am", "pm", "noon", "midnight", "evening", "morning" and so on as defined in the CLDR day period rules.

Examples

iex> Elixir.Plotex.Cldr.DateTime.Format.day_period_for ~T[06:05:54.515228], "en"
:morning1

iex> Elixir.Plotex.Cldr.DateTime.Format.day_period_for ~T[13:05:54.515228], "en"
:afternoon1

iex> Elixir.Plotex.Cldr.DateTime.Format.day_period_for ~T[21:05:54.515228], "en"
:night1

iex> Elixir.Plotex.Cldr.DateTime.Format.day_period_for ~T[21:05:54.515228], "fr"
:evening1
Link to this function

gmt_format(locale \\ Plotex.Cldr.get_locale())

gmt_format(Cldr.Locale.locale_name() | Cldr.LanguageTag.t()) ::
  {:ok, [non_neg_integer() | String.t(), ...]}

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

Arguments

Example

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

gmt_zero_format(locale \\ Plotex.Cldr.get_locale())

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

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

Arguments

Example

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

hour_format(locale \\ Plotex.Cldr.get_locale())

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

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

Arguments

Example

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

language_has_noon_and_midnight?(locale)

language_has_noon_and_midnight?(
  Cldr.LanguageTag.t()
  | Cldr.Locale.locale_name()
) :: boolean()

Returns a boolean indicating is a given language defines the notion of "noon" and "midnight"

Arguments

  • language is a binary representation of a valid and configured language in Cldr

Examples

iex> Elixir.Plotex.Cldr.DateTime.Format.language_has_noon_and_midnight? "fr"
true

iex> Elixir.Plotex.Cldr.DateTime.Format.language_has_noon_and_midnight? "en"
true

iex> Elixir.Plotex.Cldr.DateTime.Format.language_has_noon_and_midnight? "af"
false
Link to this function

time_formats(locale \\ Plotex.Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar())

time_formats(Cldr.Locale.locale_name() | Cldr.LanguageTag.t(), calendar()) ::
  {:ok, map()} | {:error, {module(), String.t()}}

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

Arguments

Examples:

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

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