use icu_datetime::fieldsets::builder::{DateFields, FieldSetBuilder, ZoneStyle};
use icu_datetime::options::{Length, TimePrecision};
#[derive(Debug, Clone, Copy, PartialEq)]
#[non_exhaustive]
pub enum Date {
Full,
Long,
Medium,
Short,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[non_exhaustive]
pub enum Time {
Full,
Long,
Medium,
Short,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[non_exhaustive]
pub(super) struct Bag {
pub date: Option<Date>,
pub time: Option<Time>,
}
impl Bag {
pub fn empty() -> Self {
Self {
date: None,
time: None,
}
}
pub(super) fn to_fieldset_builder(self) -> FieldSetBuilder {
let (date, time) = if self == Self::empty() {
(Some(Date::Short), None)
} else {
(self.date, self.time)
};
let mut builder = FieldSetBuilder::new();
if let Some(date) = date {
builder.date_fields = Some(if date == Date::Full {
DateFields::YMDE
} else {
DateFields::YMD
});
builder.length = Some(match date {
Date::Full | Date::Long => Length::Long,
Date::Medium => Length::Medium,
Date::Short => Length::Short,
});
}
if let Some(time) = time {
builder.time_precision = Some(if time == Time::Short {
TimePrecision::Minute
} else {
TimePrecision::Second
});
if time == Time::Full {
builder.zone_style = Some(ZoneStyle::SpecificLong);
} else if time == Time::Long {
builder.zone_style = Some(ZoneStyle::SpecificShort)
}
}
builder
}
}