use crate::format::FormatNumberStyle;
use crate::{
ValueFormatBoolean, ValueFormatCurrency, ValueFormatDateTime, ValueFormatNumber,
ValueFormatPercentage, ValueFormatTimeDuration,
};
use icu_locid::Locale;
pub fn create_loc_boolean_format<S: Into<String>>(name: S, locale: Locale) -> ValueFormatBoolean {
let mut v = ValueFormatBoolean::new_localized(name.into(), locale);
v.part_boolean().build();
v
}
pub fn create_loc_number_format<S: Into<String>>(
name: S,
locale: Locale,
decimal: u8,
grouping: bool,
) -> ValueFormatNumber {
let mut v = ValueFormatNumber::new_localized(name.into(), locale);
v.part_number()
.decimal_places(decimal)
.if_then(grouping, |p| p.grouping())
.build();
v
}
pub fn create_loc_number_format_fixed<S: Into<String>>(
name: S,
locale: Locale,
decimal: u8,
grouping: bool,
) -> ValueFormatNumber {
let mut v = ValueFormatNumber::new_localized(name.into(), locale);
v.part_number()
.fixed_decimal_places(decimal)
.if_then(grouping, |p| p.grouping())
.build();
v
}
pub fn create_loc_percentage_format<S: Into<String>>(
name: S,
locale: Locale,
decimal: u8,
) -> ValueFormatPercentage {
let mut v = ValueFormatPercentage::new_localized(name.into(), locale);
v.part_number().decimal_places(decimal).build();
v.part_text("%").build();
v
}
pub fn create_loc_currency_prefix<S1, S2>(
name: S1,
locale: Locale,
symbol_locale: Locale,
symbol: S2,
) -> ValueFormatCurrency
where
S1: Into<String>,
S2: Into<String>,
{
let mut v = ValueFormatCurrency::new_localized(name.into(), locale);
v.part_currency()
.locale(symbol_locale)
.symbol(symbol.into())
.build();
v.part_text(" ").build();
v.part_number()
.decimal_places(2)
.min_decimal_places(2)
.grouping()
.build();
v.part_number()
.decimal_places(2)
.min_decimal_places(2)
.grouping()
.build();
v
}
pub fn create_loc_currency_suffix<S1, S2>(
name: S1,
locale: Locale,
symbol_locale: Locale,
symbol: S2,
) -> ValueFormatCurrency
where
S1: Into<String>,
S2: Into<String>,
{
let mut v = ValueFormatCurrency::new_localized(name.into(), locale);
v.part_number()
.decimal_places(2)
.min_decimal_places(2)
.grouping()
.build();
v.part_text(" ").build();
v.part_currency()
.locale(symbol_locale)
.symbol(symbol.into())
.build();
v
}
pub fn create_loc_date_dmy_format<S: Into<String>>(name: S, locale: Locale) -> ValueFormatDateTime {
let mut v = ValueFormatDateTime::new_localized(name.into(), locale);
v.part_day().style(FormatNumberStyle::Long).build();
v.part_text(".").build();
v.part_month().style(FormatNumberStyle::Long).build();
v.part_text(".").build();
v.part_year().style(FormatNumberStyle::Long).build();
v
}
pub fn create_loc_date_mdy_format<S: Into<String>>(name: S, locale: Locale) -> ValueFormatDateTime {
let mut v = ValueFormatDateTime::new_localized(name.into(), locale);
v.part_month().style(FormatNumberStyle::Long).build();
v.part_text("/").build();
v.part_day().style(FormatNumberStyle::Long).build();
v.part_text("/").build();
v.part_year().style(FormatNumberStyle::Long).build();
v
}
pub fn create_loc_datetime_format<S: Into<String>>(name: S, locale: Locale) -> ValueFormatDateTime {
let mut v = ValueFormatDateTime::new_localized(name.into(), locale);
v.part_day().style(FormatNumberStyle::Long).build();
v.part_text(".").build();
v.part_month().style(FormatNumberStyle::Long).build();
v.part_text(".").build();
v.part_year().style(FormatNumberStyle::Long).build();
v.part_text(" ").build();
v.part_hours().style(FormatNumberStyle::Long).build();
v.part_text(":").build();
v.part_minutes().style(FormatNumberStyle::Long).build();
v.part_text(":").build();
v.part_seconds().style(FormatNumberStyle::Long).build();
v
}
pub fn create_loc_time_format<S: Into<String>>(name: S, locale: Locale) -> ValueFormatTimeDuration {
let mut v = ValueFormatTimeDuration::new_localized(name.into(), locale);
v.part_hours().style(FormatNumberStyle::Long).build();
v.part_text(":").build();
v.part_minutes().style(FormatNumberStyle::Long).build();
v.part_text(":").build();
v.part_seconds().style(FormatNumberStyle::Long).build();
v
}
pub fn create_loc_time_interval_format<S: Into<String>>(
name: S,
locale: Locale,
) -> ValueFormatTimeDuration {
let mut v = ValueFormatTimeDuration::new_localized(name.into(), locale);
v.set_truncate_on_overflow(false);
v.part_hours().style(FormatNumberStyle::Long).build();
v.part_text(":").build();
v.part_minutes().style(FormatNumberStyle::Long).build();
v.part_text(":").build();
v.part_seconds().style(FormatNumberStyle::Long).build();
v
}
pub fn create_boolean_format<S: Into<String>>(name: S) -> ValueFormatBoolean {
let mut v = ValueFormatBoolean::new_named(name.into());
v.part_boolean().build();
v
}
pub fn create_number_format<S: Into<String>>(
name: S,
decimal: u8,
grouping: bool,
) -> ValueFormatNumber {
let mut v = ValueFormatNumber::new_named(name.into());
v.part_number()
.decimal_places(decimal)
.if_then(grouping, |p| p.grouping())
.build();
v
}
pub fn create_number_format_fixed<S: Into<String>>(
name: S,
decimal: u8,
grouping: bool,
) -> ValueFormatNumber {
let mut v = ValueFormatNumber::new_named(name.into());
v.part_number()
.fixed_decimal_places(decimal)
.if_then(grouping, |p| p.grouping())
.build();
v
}
pub fn create_percentage_format<S: Into<String>>(name: S, decimal: u8) -> ValueFormatPercentage {
let mut v = ValueFormatPercentage::new_named(name.into());
v.part_number().fixed_decimal_places(decimal).build();
v.part_text("%").build();
v
}
pub fn create_currency_prefix<S1, S2>(
name: S1,
symbol_locale: Locale,
symbol: S2,
) -> ValueFormatCurrency
where
S1: Into<String>,
S2: Into<String>,
{
let mut v = ValueFormatCurrency::new_named(name.into());
v.part_currency()
.locale(symbol_locale)
.symbol(symbol.into())
.build();
v.part_text(" ").build();
v.part_number().fixed_decimal_places(2).grouping().build();
v
}
pub fn create_currency_suffix<S1, S2>(
name: S1,
symbol_locale: Locale,
symbol: S2,
) -> ValueFormatCurrency
where
S1: Into<String>,
S2: Into<String>,
{
let mut v = ValueFormatCurrency::new_named(name.into());
v.part_number().fixed_decimal_places(2).grouping().build();
v.part_text(" ").build();
v.part_currency()
.locale(symbol_locale)
.symbol(symbol.into())
.build();
v
}
pub fn create_date_iso_format<S: Into<String>>(name: S) -> ValueFormatDateTime {
let mut v = ValueFormatDateTime::new_named(name.into());
v.part_year().style(FormatNumberStyle::Long).build();
v.part_text("-").build();
v.part_month().style(FormatNumberStyle::Long).build();
v.part_text("-").build();
v.part_day().style(FormatNumberStyle::Long).build();
v
}
pub fn create_date_dmy_format<S: Into<String>>(name: S) -> ValueFormatDateTime {
let mut v = ValueFormatDateTime::new_named(name.into());
v.part_day().style(FormatNumberStyle::Long).build();
v.part_text(".").build();
v.part_month().style(FormatNumberStyle::Long).build();
v.part_text(".").build();
v.part_year().style(FormatNumberStyle::Long).build();
v
}
pub fn create_date_mdy_format<S: Into<String>>(name: S) -> ValueFormatDateTime {
let mut v = ValueFormatDateTime::new_named(name.into());
v.part_month().style(FormatNumberStyle::Long).build();
v.part_text("/").build();
v.part_day().style(FormatNumberStyle::Long).build();
v.part_text("/").build();
v.part_year().style(FormatNumberStyle::Long).build();
v
}
pub fn create_datetime_format<S: Into<String>>(name: S) -> ValueFormatDateTime {
let mut v = ValueFormatDateTime::new_named(name.into());
v.part_year().style(FormatNumberStyle::Long).build();
v.part_text("-").build();
v.part_month().style(FormatNumberStyle::Long).build();
v.part_text("-").build();
v.part_day().style(FormatNumberStyle::Long).build();
v.part_text(" ").build();
v.part_hours().style(FormatNumberStyle::Long).build();
v.part_text(":").build();
v.part_minutes().style(FormatNumberStyle::Long).build();
v.part_text(":").build();
v.part_seconds().style(FormatNumberStyle::Long).build();
v
}
pub fn create_time_of_day_format<S: Into<String>>(name: S) -> ValueFormatTimeDuration {
let mut v = ValueFormatTimeDuration::new_named(name.into());
v.part_hours().style(FormatNumberStyle::Long).build();
v.part_text(":").build();
v.part_minutes().style(FormatNumberStyle::Long).build();
v.part_text(":").build();
v.part_seconds().style(FormatNumberStyle::Long).build();
v
}
pub fn create_time_interval_format<S: Into<String>>(name: S) -> ValueFormatTimeDuration {
let mut v = ValueFormatTimeDuration::new_named(name.into());
v.set_truncate_on_overflow(false);
v.part_hours().style(FormatNumberStyle::Long).build();
v.part_text(":").build();
v.part_minutes().style(FormatNumberStyle::Long).build();
v.part_text(":").build();
v.part_seconds().style(FormatNumberStyle::Long).build();
v
}