use crate::fields::Field;
use crate::fields::FieldSymbol;
use crate::input::CalendarError;
use crate::pattern::PatternError;
use displaydoc::Display;
use icu_calendar::any_calendar::AnyCalendarKind;
use icu_calendar::types::MonthCode;
use icu_decimal::DecimalError;
use icu_plurals::PluralsError;
use icu_provider::DataError;
#[cfg(feature = "std")]
impl std::error::Error for DateTimeError {}
#[derive(Display, Debug, Copy, Clone, PartialEq)]
#[non_exhaustive]
pub enum DateTimeError {
#[displaydoc("{0}")]
Pattern(PatternError),
#[displaydoc("{0}")]
Format(core::fmt::Error),
#[displaydoc("{0}")]
Data(DataError),
#[displaydoc("Missing input field")]
MissingInputField(Option<&'static str>),
#[displaydoc("{0}")]
#[cfg(feature = "experimental")]
Skeleton(crate::skeleton::SkeletonError),
#[displaydoc("Unsupported field: {0:?}")]
UnsupportedField(FieldSymbol),
#[displaydoc("Unsupported field: {0:?}")]
UnsupportedFormattingField(Field),
#[displaydoc("Unsupported options")]
UnsupportedOptions,
#[displaydoc("{0}")]
PluralRules(PluralsError),
#[displaydoc("{0}")]
DateTimeInput(CalendarError),
#[displaydoc("Data file missing weekday symbol for weekday {0}")]
MissingWeekdaySymbol(usize),
#[displaydoc("Data file missing month symbol for month code {0}")]
MissingMonthSymbol(MonthCode),
#[displaydoc("Missing FixedDecimalFormatter")]
FixedDecimal,
#[displaydoc("{0}")]
FixedDecimalFormatter(DecimalError),
#[displaydoc("DateTimeFormatter for {0} calendar was given a {1:?} calendar")]
MismatchedAnyCalendar(AnyCalendarKind, Option<AnyCalendarKind>),
#[displaydoc("Missing date symbols")]
MissingDateSymbols,
#[displaydoc("Missing time symbols")]
MissingTimeSymbols,
#[displaydoc("ordinal_rules must be set for PatternPlurals::MultipleVariants")]
MissingOrdinalRules,
#[displaydoc("Missing names for {0:?}")]
MissingNames(Field),
#[displaydoc("Duplicate field: {0:?}")]
DuplicateField(Field),
}
#[derive(Display, Debug, Copy, Clone, PartialEq)]
#[displaydoc("DateTimeFormatter for {this_kind} calendar was given a {date_kind:?} calendar")]
#[non_exhaustive]
pub struct MismatchedCalendarError {
pub this_kind: AnyCalendarKind,
pub date_kind: Option<AnyCalendarKind>,
}
impl From<PatternError> for DateTimeError {
fn from(e: PatternError) -> Self {
DateTimeError::Pattern(e)
}
}
impl From<DataError> for DateTimeError {
fn from(e: DataError) -> Self {
DateTimeError::Data(e)
}
}
impl From<core::fmt::Error> for DateTimeError {
fn from(e: core::fmt::Error) -> Self {
DateTimeError::Format(e)
}
}
impl From<PluralsError> for DateTimeError {
fn from(e: PluralsError) -> Self {
DateTimeError::PluralRules(e)
}
}
impl From<CalendarError> for DateTimeError {
fn from(e: CalendarError) -> Self {
DateTimeError::DateTimeInput(e)
}
}
impl From<DecimalError> for DateTimeError {
fn from(e: DecimalError) -> Self {
DateTimeError::FixedDecimalFormatter(e)
}
}
impl From<MismatchedCalendarError> for DateTimeError {
fn from(e: MismatchedCalendarError) -> Self {
DateTimeError::MismatchedAnyCalendar(e.this_kind, e.date_kind)
}
}