View Source Bonfire.Common.Localise.Cldr.DateTime.Format (Bonfire v0.9.10-classic-beta.169)
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 list of the date_time format IDs that are available in all known locales.
Returns a map of the available date formats for a given locale and calendar.
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 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 available time formats for a given locale and calendar.
Returns a map of the standard time formats for a given locale and calendar.
Types
Functions
calendars_for(locale \\ Bonfire.Common.Localise.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
locale
is any locale returned byCldr.known_locale_names/0
or aCldr.LanguageTag.t/0
. The default isCldr.get_locale/0
.
Example
iex> Bonfire.Common.Localise.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]}
@spec common_date_time_format_names() :: [Cldr.DateTime.Format.format_id()]
Returns a list of the date_time format IDs that are available in all known locales.
The format IDs returned by common_date_time_format_names/0
are guaranteed to be available in all known locales,
Example:
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.common_date_time_format_names()
[:Bh, :Bhm, :Bhms, :E, :EBhm, :EBhms, :EHm, :EHms, :Ed, :Ehm, :Ehms, :Gy,
:GyMMM, :GyMMMEd, :GyMMMd, :GyMd, :H, :Hm, :Hms, :Hmsv, :Hmv, :M, :MEd, :MMM,
:MMMEd, :MMMMW, :MMMMd, :MMMd, :Md, :d, :h, :hm, :hms, :hmsv, :hmv, :ms, :y,
:yM, :yMEd, :yMMM, :yMMMEd, :yMMMM, :yMMMd, :yMd, :yQQQ, :yQQQQ, :yw]
date_available_formats(locale \\ Bonfire.Common.Localise.Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar())
View Source@spec date_available_formats(Cldr.Locale.locale_reference(), calendar()) :: {:ok, formats()} | {:error, {module(), String.t()}}
Returns a map of the available date formats for a given locale and calendar.
Arguments
locale
is any locale returned byCldr.known_locale_names/0
or aCldr.LanguageTag.t/0
. The default isCldr.get_locale/0
.calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
.
Examples:
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.date_available_formats "en"
date_formats(locale \\ Bonfire.Common.Localise.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
or aCldr.LanguageTag.t/0
. The default isCldr.get_locale/0
.calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
.
Examples:
iex> Bonfire.Common.Localise.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> Bonfire.Common.Localise.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 \\ Bonfire.Common.Localise.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
or aCldr.LanguageTag.t/0
. The default isCldr.get_locale/0
.calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
,
Examples:
iex> Bonfire.Common.Localise.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> Bonfire.Common.Localise.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 \\ Bonfire.Common.Localise.Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar())
View Source@spec date_time_available_formats(Cldr.Locale.locale_reference(), calendar()) :: {:ok, formats()} | {:error, {module(), String.t()}}
Returns a map of the available datetime formats for a given locale and calendar.
Arguments
locale
is any locale returned byCldr.known_locale_names/0
or aCldr.LanguageTag.t/0
. The default isCldr.get_locale/0
.calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
.
Examples:
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.date_time_available_formats "en"
{:ok,
%{
yw: %{
other: "'week' w 'of' Y",
one: "'week' w 'of' Y",
pluralize: :week_of_year
},
GyMMMEd: "E, MMM d, y G",
Hms: "HH:mm:ss",
MMMMW: %{
other: "'week' W 'of' MMMM",
one: "'week' W 'of' MMMM",
pluralize: :week_of_month
},
E: "ccc",
MMMd: "MMM d",
yMEd: "E, M/d/y",
yQQQ: "QQQ y",
Ehm: %{unicode: "E h:mm a", ascii: "E h:mm a"},
M: "L",
hm: %{unicode: "h:mm a", ascii: "h:mm a"},
yM: "M/y",
GyMMMd: "MMM d, y G",
GyMd: "M/d/y G",
Gy: "y G",
Hm: "HH:mm",
EBhms: "E h:mm:ss B",
d: "d",
hms: %{unicode: "h:mm:ss a", ascii: "h:mm:ss a"},
Ed: "d E",
Ehms: %{unicode: "E h:mm:ss a", ascii: "E h:mm:ss a"},
EHms: "E HH:mm:ss",
Bh: "h B",
h: %{unicode: "h a", ascii: "h a"},
Bhms: "h:mm:ss B",
Hmv: "HH:mm v",
hmv: %{unicode: "h:mm a v", ascii: "h:mm a v"},
yMd: "M/d/y",
ms: "mm:ss",
MMM: "LLL",
y: "y",
Bhm: "h:mm B",
yMMM: "MMM y",
yQQQQ: "QQQQ y",
yMMMEd: "E, MMM d, y",
yMMMM: "MMMM y",
EBhm: "E h:mm B",
Hmsv: "HH:mm:ss v",
yMMMd: "MMM d, y",
MEd: "E, M/d",
EHm: "E HH:mm",
GyMMM: "MMM y G",
hmsv: %{unicode: "h:mm:ss a v", ascii: "h:mm:ss a v"},
H: "HH",
Md: "M/d",
MMMEd: "E, MMM d",
MMMMd: "MMMM d"
}}
date_time_formats(locale \\ Bonfire.Common.Localise.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
or aCldr.LanguageTag.t/0
. The default isCldr.get_locale/0
.calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
.
Examples:
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.date_time_formats(:en)
{:ok, %Cldr.DateTime.Formats{
full: "{1}, {0}",
long: "{1}, {0}",
medium: "{1}, {0}",
short: "{1}, {0}"
}}
iex> Bonfire.Common.Localise.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 \\ Bonfire.Common.Localise.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/0
. The default isCldr.get_locale/0
.calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
.
Examples:
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.date_time_interval_fallback(:en, :gregorian)
[0, " – ", 1]
date_time_interval_formats(locale \\ Bonfire.Common.Localise.Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar())
View Source@spec date_time_interval_formats(Cldr.Locale.locale_reference(), calendar()) :: {:ok, formats()} | {:error, {module(), String.t()}}
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
. The default isCldr.get_locale/0
.calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
.
Examples:
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.date_time_interval_formats(:en, :gregorian)
{:ok,
%{
h: %{a: ["h a – ", "h a"], h: ["h – ", "h a"]},
d: %{d: ["d – ", "d"]},
y: %{y: ["y – ", "y"]},
M: %{M: ["M – ", "M"]},
Bh: %{h: ["h – ", "h B"], B: ["h B – ", "h B"]},
Bhm: %{
m: ["h:mm – ", "h:mm B"],
h: ["h:mm – ", "h:mm B"],
B: ["h:mm B – ", "h:mm B"]
},
Gy: %{y: ["y – ", "y G"], G: ["y G – ", "y G"]},
GyMMM: %{
y: ["MMM y – ", "MMM y G"],
M: ["MMM – ", "MMM y G"],
G: ["MMM y G – ", "MMM y G"]
},
GyMMMEd: %{
d: ["E, MMM d – ", "E, MMM d, y G"],
y: ["E, MMM d, y – ", "E, MMM d, y G"],
M: ["E, MMM d – ", "E, MMM d, y G"],
G: ["E, MMM d, y G – ", "E, MMM d, y G"]
},
GyMMMd: %{
d: ["MMM d – ", "d, y G"],
y: ["MMM d, y – ", "MMM d, y G"],
M: ["MMM d – ", "MMM d, y G"],
G: ["MMM d, y G – ", "MMM d, y G"]
},
GyMd: %{
d: ["M/d/y – ", "M/d/y G"],
y: ["M/d/y – ", "M/d/y G"],
M: ["M/d/y – ", "M/d/y G"],
G: ["M/d/y G – ", "M/d/y G"]
},
H: %{H: ["HH – ", "HH"]},
Hm: %{m: ["HH:mm – ", "HH:mm"], H: ["HH:mm – ", "HH:mm"]},
Hmv: %{m: ["HH:mm – ", "HH:mm v"], H: ["HH:mm – ", "HH:mm v"]},
MEd: %{d: ["E, M/d – ", "E, M/d"], M: ["E, M/d – ", "E, M/d"]},
MMM: %{M: ["MMM – ", "MMM"]},
MMMEd: %{
d: ["E, MMM d – ", "E, MMM d"],
M: ["E, MMM d – ", "E, MMM d"]
},
MMMd: %{d: ["MMM d – ", "d"], M: ["MMM d – ", "MMM d"]},
Md: %{d: ["M/d – ", "M/d"], M: ["M/d – ", "M/d"]},
hm: %{
m: ["h:mm – ", "h:mm a"],
a: ["h:mm a – ", "h:mm a"],
h: ["h:mm – ", "h:mm a"]
},
hmv: %{
m: ["h:mm – ", "h:mm a v"],
a: ["h:mm a – ", "h:mm a v"],
h: ["h:mm – ", "h:mm a v"]
},
yM: %{y: ["M/y – ", "M/y"], M: ["M/y – ", "M/y"]},
yMEd: %{
d: ["E, M/d/y – ", "E, M/d/y"],
y: ["E, M/d/y – ", "E, M/d/y"],
M: ["E, M/d/y – ", "E, M/d/y"]
},
yMMM: %{y: ["MMM y – ", "MMM y"], M: ["MMM – ", "MMM y"]},
yMMMEd: %{
d: ["E, MMM d – ", "E, MMM d, y"],
y: ["E, MMM d, y – ", "E, MMM d, y"],
M: ["E, MMM d – ", "E, MMM d, y"]
},
yMMMM: %{y: ["MMMM y – ", "MMMM y"], M: ["MMMM – ", "MMMM y"]},
yMMMd: %{
d: ["MMM d – ", "d, y"],
y: ["MMM d, y – ", "MMM d, y"],
M: ["MMM d – ", "MMM d, y"]
},
yMd: %{
d: ["M/d/y – ", "M/d/y"],
y: ["M/d/y – ", "M/d/y"],
M: ["M/d/y – ", "M/d/y"]
},
GyM: %{
y: ["M/y – ", "M/y G"],
M: ["M/y – ", "M/y G"],
G: ["M/y G – ", "M/y G"]
},
GyMEd: %{
d: ["E, M/d/y – ", "E, M/d/y G"],
y: ["E, M/d/y – ", "E, M/d/y G"],
M: ["E, M/d/y – ", "E, M/d/y G"],
G: ["E, M/d/y G – ", "E, M/d/y G"]
},
Hv: %{H: ["HH – ", "HH v"]},
hv: %{a: ["h a – ", "h a v"], h: ["h – ", "h a v"]}
}}
@spec day_period_for( Calendar.time(), Cldr.LanguageTag.t() | String.t() | Cldr.Locale.locale_name() ) :: atom() | {:error, {module(), String.t()}}
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> Bonfire.Common.Localise.Cldr.DateTime.Format.day_period_for ~T[06:05:54.515228], :en
:morning1
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.day_period_for ~T[13:05:54.515228], :en
:afternoon1
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.day_period_for ~T[21:05:54.515228], :en
:night1
iex> Bonfire.Common.Localise.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(), ...]} | {:error, {module(), 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
or aCldr.LanguageTag.t/0
. The default isCldr.get_locale/0
.
Example
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.gmt_format(:en)
{:ok, ["GMT", 0]}
gmt_zero_format(locale \\ Bonfire.Common.Localise.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
locale
is any locale returned byCldr.known_locale_names/0
or aCldr.LanguageTag.t/0
. The default isCldr.get_locale/0
.
Example
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.gmt_zero_format(:en)
{:ok, "GMT"}
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.gmt_zero_format(:fr)
{:ok, "UTC"}
@spec hour_format(Cldr.Locale.locale_reference()) :: {:ok, {String.t(), String.t()}} | {:error, {module(), 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
or aCldr.LanguageTag.t/0
. The default isCldr.get_locale/0
.
Example
iex> Bonfire.Common.Localise.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() | {:error, {module(), String.t()}}
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> Bonfire.Common.Localise.Cldr.DateTime.Format.language_has_noon_and_midnight? :fr
true
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.language_has_noon_and_midnight? :en
true
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.language_has_noon_and_midnight? :af
false
time_available_formats(locale \\ Bonfire.Common.Localise.Cldr.get_locale(), calendar \\ Cldr.Calendar.default_cldr_calendar())
View Source@spec time_available_formats(Cldr.Locale.locale_reference(), calendar()) :: {:ok, formats()} | {:error, {module(), String.t()}}
Returns a map of the available time formats for a given locale and calendar.
Arguments
locale
is any locale returned byCldr.known_locale_names/0
or aCldr.LanguageTag.t/0
. The default isCldr.get_locale/0
.calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
.
Examples:
iex> Bonfire.Common.Localise.Cldr.DateTime.Format.time_available_formats :en
time_formats(locale \\ Bonfire.Common.Localise.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
or aCldr.LanguageTag.t/0
. The default isCldr.get_locale/0
.calendar
is any calendar returned byCldr.DateTime.Format.calendars_for/1
The default is:gregorian
.
Examples:
iex> Bonfire.Common.Localise.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> Bonfire.Common.Localise.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"
}}