View Source Mobilizon.Cldr.DateTime.Format (Mobilizon v5.0.0-beta.1)

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.

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 standard datetime "at" 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 positive 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.

Types

@type calendar() :: atom()
@type formats() :: map()

Functions

Link to this function

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

View Source
@spec calendars_for(Cldr.Locale.locale_reference()) ::
  {:ok, [calendar(), ...]} | {:error, {module(), String.t()}}

Returns a list of calendars defined for a given locale.

Arguments

Example

iex> Mobilizon.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 \\ Mobilizon.Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar())

View Source
@spec date_formats(Cldr.Locale.locale_reference(), calendar()) ::
  {:ok, map()} | {:error, {module(), String.t()}}

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

Arguments

Examples:

iex> Mobilizon.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> Mobilizon.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_at_formats(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar())

View Source
@spec date_time_at_formats(Cldr.Locale.locale_reference(), calendar()) ::
  {:ok, map()} | {:error, {module(), String.t()}}

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

An "at" format is one where the datetime is formatted with the date part separated from the time part by a localized version of "at".

Arguments

Examples:

iex> Mobilizon.Cldr.DateTime.Format.date_time_at_formats(:en)
{:ok, %Cldr.DateTime.Formats{
  full: "{1} 'at' {0}",
  long: "{1} 'at' {0}",
  medium: "{1}, {0}",
  short: "{1}, {0}"}
}

iex> Mobilizon.Cldr.DateTime.Format.date_time_at_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

date_time_available_formats(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar())

View Source
@spec date_time_available_formats(Cldr.Locale.locale_reference(), calendar()) ::
  {:ok, formats()}

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

Arguments

Examples:

iex> Mobilizon.Cldr.DateTime.Format.date_time_available_formats "en"
{
  :ok,
  %{
    d: "d",
    h: "h a",
    hm: "h:mm a",
    hms: "h:mm:ss a",
    hmsv: "h:mm:ss a v",
    hmv: "h:mm a v",
    ms: "mm:ss",
    y: "y",
    yw: %{one: "'week' w 'of' Y", other: "'week' w 'of' Y"},
    Bh: "h B",
    Bhm: "h:mm B",
    Bhms: "h:mm:ss B",
    E: "ccc",
    EBhm: "E h:mm B",
    EBhms: "E h:mm:ss B",
    EHm: "E HH:mm",
    EHms: "E HH:mm:ss",
    Ed: "d E",
    Ehm: "E h:mm a",
    Ehms: "E h:mm:ss a",
    Gy: "y G",
    GyMMM: "MMM y G",
    GyMMMEd: "E, MMM d, y G",
    GyMMMd: "MMM d, y G",
    GyMd: "M/d/y G",
    H: "HH",
    Hm: "HH:mm",
    Hms: "HH:mm:ss",
    Hmsv: "HH:mm:ss v",
    Hmv: "HH:mm v",
    M: "L",
    MEd: "E, M/d",
    MMM: "LLL",
    MMMEd: "E, MMM d",
    MMMMW: %{one: "'week' W 'of' MMMM", other: "'week' W 'of' MMMM"},
    MMMMd: "MMMM d",
    MMMd: "MMM d",
    Md: "M/d",
    yM: "M/y",
    yMEd: "E, M/d/y",
    yMMM: "MMM y",
    yMMMEd: "E, MMM d, y",
    yMMMM: "MMMM y",
    yMMMd: "MMM d, y",
    yMd: "M/d/y",
    yQQQ: "QQQ y",
    yQQQQ: "QQQQ y"
  }
}
Link to this function

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

View Source
@spec date_time_formats(Cldr.Locale.locale_reference(), calendar()) ::
  {:ok, map()} | {:error, {module(), String.t()}}

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

Arguments

Examples:

iex> Mobilizon.Cldr.DateTime.Format.date_time_formats(:en)
{:ok, %Cldr.DateTime.Formats{
  full: "{1}, {0}",
  long: "{1}, {0}",
  medium: "{1}, {0}",
  short: "{1}, {0}"
}}

iex> Mobilizon.Cldr.DateTime.Format.date_time_formats(:en, :buddhist)
{:ok, %Cldr.DateTime.Formats{
  full: "{1}, {0}",
  long: "{1}, {0}",
  medium: "{1}, {0}",
  short: "{1}, {0}"
}}
Link to this function

date_time_interval_fallback(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar())

View Source
@spec date_time_interval_fallback(Cldr.Locale.locale_reference(), calendar()) ::
  list() | {:error, {module(), String.t()}}

Returns the fallback format for a given locale and calendar type

Arguments

Examples:

iex> Mobilizon.Cldr.DateTime.Format.date_time_interval_fallback :en, :gregorian
[0, " – ", 1]
Link to this function

date_time_interval_formats(locale \\ Mobilizon.Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar())

View Source
@spec date_time_interval_formats(Cldr.Locale.locale_reference(), calendar()) ::
  {:ok, formats()}

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

Arguments

Examples:

Link to this function

day_period_for(time, language)

View Source
@spec day_period_for(
  Calendar.time(),
  Cldr.LanguageTag.t() | String.t() | Cldr.Locale.locale_name()
) ::
  atom()

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> Mobilizon.Cldr.DateTime.Format.day_period_for ~T[06:05:54.515228], :en
:morning1

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

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

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

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

View Source
@spec gmt_format(Cldr.Locale.locale_reference()) ::
  {: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> Mobilizon.Cldr.DateTime.Format.gmt_format :en
{:ok, ["GMT", 0]}
Link to this function

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

View Source
@spec gmt_zero_format(Cldr.Locale.locale_reference()) ::
  {: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> Mobilizon.Cldr.DateTime.Format.gmt_zero_format :en
{:ok, "GMT"}

iex> Mobilizon.Cldr.DateTime.Format.gmt_zero_format :fr
{:ok, "UTC"}
Link to this function

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

View Source
@spec hour_format(Cldr.Locale.locale_reference()) :: {:ok, {String.t(), String.t()}}

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

Arguments

Example

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

language_has_noon_and_midnight?(locale)

View Source
@spec language_has_noon_and_midnight?(
  Cldr.LanguageTag.t()
  | String.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> Mobilizon.Cldr.DateTime.Format.language_has_noon_and_midnight? :fr
true

iex> Mobilizon.Cldr.DateTime.Format.language_has_noon_and_midnight? :en
true

iex> Mobilizon.Cldr.DateTime.Format.language_has_noon_and_midnight? :af
false
Link to this function

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

View Source
@spec time_formats(Cldr.Locale.locale_reference(), calendar()) ::
  {:ok, map()} | {:error, {module(), String.t()}}

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

Arguments

Examples:

iex> Mobilizon.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> Mobilizon.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"
}}