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 fallback format for a given locale and calendar type
Returns a map of the interval 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
Functions
@spec calendars_for(Cldr.Locale.locale_reference()) :: {:ok, [calendar(), ...]} | {:error, {module(), String.t()}}
Returns a list of calendars defined for a given locale.
Arguments
locale
is any valid locale name returned byCldr.known_locale_names/0
or aCldr.LanguageTag
struct. The default isCldr.get_locale/0
.
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]}
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
locale
is any locale returned byCldr.known_locale_names/0
.calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
.
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"
}}
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
locale
is any locale returned byCldr.known_locale_names/0
.calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
,
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}"}
}
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
locale
is any locale returned byCldr.known_locale_names/0
or aCldr.LanguageTag.t()
calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
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"
}
}
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
locale
is any locale returned byCldr.known_locale_names/0
.calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
.
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}"
}}
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
locale
is any locale returned byCldr.known_locale_names/0
or aCldr.LanguageTag.t()
calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
Examples:
iex> Mobilizon.Cldr.DateTime.Format.date_time_interval_fallback :en, :gregorian
[0, " – ", 1]
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
locale
is any locale returned byCldr.known_locale_names/0
or aCldr.LanguageTag.t/0
calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
Examples:
@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 anyTime.t
or a map with at least:hour
,:minute
and:second
keyslanguage
is a binary representation of a valid and configured language inCldr
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
@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
locale
is any locale returned byCldr.known_locale_names/0
Example
iex> Mobilizon.Cldr.DateTime.Format.gmt_format :en
{:ok, ["GMT", 0]}
@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
locale
is any locale returned byCldr.known_locale_names/0
Example
iex> Mobilizon.Cldr.DateTime.Format.gmt_zero_format :en
{:ok, "GMT"}
iex> Mobilizon.Cldr.DateTime.Format.gmt_zero_format :fr
{:ok, "UTC"}
@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
locale
is any locale returned byCldr.known_locale_names/0
Example
iex> Mobilizon.Cldr.DateTime.Format.hour_format "en"
{:ok, {"+HH:mm", "-HH:mm"}}
@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 inCldr
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
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
locale
is any locale returned byCldr.known_locale_names/0
.calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
.
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"
}}