Skip to content

Commit

Permalink
Remove more obsolete datetime types (#5552)
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Sep 18, 2024
1 parent dd5a961 commit 987c364
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 465 deletions.
103 changes: 0 additions & 103 deletions components/datetime/src/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::provider::calendar::*;
use icu_calendar::any_calendar::AnyCalendarKind;
use icu_calendar::chinese::Chinese;
use icu_calendar::roc::Roc;
Expand All @@ -12,10 +11,6 @@ use icu_calendar::{
islamic::IslamicUmmAlQura, japanese::Japanese, japanese::JapaneseExtended, persian::Persian,
Gregorian,
};
use icu_locale_core::{
extensions::unicode::{value, Value},
subtags::{subtag, Subtag},
};
use icu_provider::prelude::*;

use crate::provider::neo::*;
Expand Down Expand Up @@ -43,19 +38,6 @@ pub trait InternalCldrCalendar {}
/// including in SemVer minor releases. Do not implement this trait in userland.
/// </div>
pub trait CldrCalendar: InternalCldrCalendar {
/// The Unicode BCP 47 identifier for the calendar's skeleton
/// If multiple BCP 47 identifiers work, this should be
/// the default one when no others are provided
///
/// If `is_identifier_allowed_for_calendar()` is set, this only is used for loading skeletons data
const DEFAULT_BCP_47_IDENTIFIER: Value;

/// The data marker for loading symbols for this calendar.
type DateSymbolsV1Marker: DataMarker<DataStruct = DateSymbolsV1<'static>>;

/// The data marker for loading length-patterns for this calendar.
type DateLengthsV1Marker: DataMarker<DataStruct = DateLengthsV1<'static>>;

/// The data marker for loading year symbols for this calendar.
type YearNamesV1Marker: DataMarker<DataStruct = YearNamesV1<'static>>;

Expand All @@ -64,22 +46,6 @@ pub trait CldrCalendar: InternalCldrCalendar {

/// The data marker for loading skeleton patterns for this calendar.
type SkeletaV1Marker: DataMarker<DataStruct = PackedSkeletonDataV1<'static>>;

/// Checks if a given BCP 47 identifier is allowed to be used with this calendar
///
/// By default, just checks against DEFAULT_BCP_47_IDENTIFIER
fn is_identifier_allowed_for_calendar(value: &Value) -> bool {
*value == Self::DEFAULT_BCP_47_IDENTIFIER
}
}

/// Check if the provided value is of the form `islamic-{subcal}`
fn is_islamic_subcal(value: &Value, subcal: Subtag) -> bool {
if let &[first, second] = value.as_subtags_slice() {
first == *"islamic" && second == subcal
} else {
false
}
}

/// A calendar that can never exist.
Expand All @@ -91,84 +57,54 @@ fn is_islamic_subcal(value: &Value, subcal: Subtag) -> bool {
pub enum NeverCalendar {}

impl CldrCalendar for NeverCalendar {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("never");
type DateSymbolsV1Marker = NeverMarker<DateSymbolsV1<'static>>;
type DateLengthsV1Marker = NeverMarker<DateLengthsV1<'static>>;
type YearNamesV1Marker = NeverMarker<YearNamesV1<'static>>;
type MonthNamesV1Marker = NeverMarker<MonthNamesV1<'static>>;
type SkeletaV1Marker = NeverMarker<PackedSkeletonDataV1<'static>>;
}

impl CldrCalendar for Buddhist {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("buddhist");
type DateSymbolsV1Marker = BuddhistDateSymbolsV1Marker;
type DateLengthsV1Marker = BuddhistDateLengthsV1Marker;
type YearNamesV1Marker = BuddhistYearNamesV1Marker;
type MonthNamesV1Marker = BuddhistMonthNamesV1Marker;
type SkeletaV1Marker = BuddhistDateNeoSkeletonPatternsV1Marker;
}

impl CldrCalendar for Chinese {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("chinese");
type DateSymbolsV1Marker = ChineseDateSymbolsV1Marker;
type DateLengthsV1Marker = ChineseDateLengthsV1Marker;
type YearNamesV1Marker = ChineseYearNamesV1Marker;
type MonthNamesV1Marker = ChineseMonthNamesV1Marker;
type SkeletaV1Marker = ChineseDateNeoSkeletonPatternsV1Marker;
}

impl CldrCalendar for Coptic {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("coptic");
type DateSymbolsV1Marker = CopticDateSymbolsV1Marker;
type DateLengthsV1Marker = CopticDateLengthsV1Marker;
type YearNamesV1Marker = CopticYearNamesV1Marker;
type MonthNamesV1Marker = CopticMonthNamesV1Marker;
type SkeletaV1Marker = CopticDateNeoSkeletonPatternsV1Marker;
}

impl CldrCalendar for Dangi {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("dangi");
type DateSymbolsV1Marker = DangiDateSymbolsV1Marker;
type DateLengthsV1Marker = DangiDateLengthsV1Marker;
type YearNamesV1Marker = DangiYearNamesV1Marker;
type MonthNamesV1Marker = DangiMonthNamesV1Marker;
type SkeletaV1Marker = DangiDateNeoSkeletonPatternsV1Marker;
}

impl CldrCalendar for Ethiopian {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("ethiopic");
type DateSymbolsV1Marker = EthiopianDateSymbolsV1Marker;
type DateLengthsV1Marker = EthiopianDateLengthsV1Marker;
type YearNamesV1Marker = EthiopianYearNamesV1Marker;
type MonthNamesV1Marker = EthiopianMonthNamesV1Marker;
type SkeletaV1Marker = EthiopianDateNeoSkeletonPatternsV1Marker;
fn is_identifier_allowed_for_calendar(value: &Value) -> bool {
*value == value!("ethiopic") || *value == value!("ethioaa")
}
}

impl CldrCalendar for Gregorian {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("gregory");
type DateSymbolsV1Marker = GregorianDateSymbolsV1Marker;
type DateLengthsV1Marker = GregorianDateLengthsV1Marker;
type YearNamesV1Marker = GregorianYearNamesV1Marker;
type MonthNamesV1Marker = GregorianMonthNamesV1Marker;
type SkeletaV1Marker = GregorianDateNeoSkeletonPatternsV1Marker;
}

impl CldrCalendar for Hebrew {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("hebrew");
type DateSymbolsV1Marker = HebrewDateSymbolsV1Marker;
type DateLengthsV1Marker = HebrewDateLengthsV1Marker;
type YearNamesV1Marker = HebrewYearNamesV1Marker;
type MonthNamesV1Marker = HebrewMonthNamesV1Marker;
type SkeletaV1Marker = HebrewDateNeoSkeletonPatternsV1Marker;
}

impl CldrCalendar for Indian {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("indian");
type DateSymbolsV1Marker = IndianDateSymbolsV1Marker;
type DateLengthsV1Marker = IndianDateLengthsV1Marker;
type YearNamesV1Marker = IndianYearNamesV1Marker;
type MonthNamesV1Marker = IndianMonthNamesV1Marker;
type SkeletaV1Marker = IndianDateNeoSkeletonPatternsV1Marker;
Expand All @@ -178,87 +114,48 @@ impl CldrCalendar for IslamicCivil {
// this value is not actually a valid identifier for this calendar,
// however since we are overriding is_identifier_allowed_for_calendar we are using
// this solely for its effects on skeleton data loading
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("islamic");
type DateSymbolsV1Marker = IslamicDateSymbolsV1Marker;
type DateLengthsV1Marker = IslamicDateLengthsV1Marker;
type YearNamesV1Marker = IslamicYearNamesV1Marker;
type MonthNamesV1Marker = IslamicMonthNamesV1Marker;
type SkeletaV1Marker = IslamicDateNeoSkeletonPatternsV1Marker;
fn is_identifier_allowed_for_calendar(value: &Value) -> bool {
*value == value!("islamicc") || is_islamic_subcal(value, subtag!("civil"))
}
}

impl CldrCalendar for IslamicObservational {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("islamic");
type DateSymbolsV1Marker = IslamicDateSymbolsV1Marker;
type DateLengthsV1Marker = IslamicDateLengthsV1Marker;
type YearNamesV1Marker = IslamicYearNamesV1Marker;
type MonthNamesV1Marker = IslamicMonthNamesV1Marker;
type SkeletaV1Marker = IslamicDateNeoSkeletonPatternsV1Marker;
}

impl CldrCalendar for IslamicTabular {
// this value is not actually a valid identifier for this calendar,
// however since we are overriding is_identifier_allowed_for_calendar we are using
// this solely for its effects on skeleton data loading
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("islamic");
type DateSymbolsV1Marker = IslamicDateSymbolsV1Marker;
type DateLengthsV1Marker = IslamicDateLengthsV1Marker;
type YearNamesV1Marker = IslamicYearNamesV1Marker;
type MonthNamesV1Marker = IslamicMonthNamesV1Marker;
type SkeletaV1Marker = IslamicDateNeoSkeletonPatternsV1Marker;
fn is_identifier_allowed_for_calendar(value: &Value) -> bool {
is_islamic_subcal(value, subtag!("tbla"))
}
}

impl CldrCalendar for IslamicUmmAlQura {
// this value is not actually a valid identifier for this calendar,
// however since we are overriding is_identifier_allowed_for_calendar we are using
// this solely for its effects on skeleton data loading
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("islamic");
type DateSymbolsV1Marker = IslamicDateSymbolsV1Marker;
type DateLengthsV1Marker = IslamicDateLengthsV1Marker;
type YearNamesV1Marker = IslamicYearNamesV1Marker;
type MonthNamesV1Marker = IslamicMonthNamesV1Marker;
type SkeletaV1Marker = IslamicDateNeoSkeletonPatternsV1Marker;
fn is_identifier_allowed_for_calendar(value: &Value) -> bool {
is_islamic_subcal(value, subtag!("umalqura"))
}
}

impl CldrCalendar for Japanese {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("japanese");
type DateSymbolsV1Marker = JapaneseDateSymbolsV1Marker;
type DateLengthsV1Marker = JapaneseDateLengthsV1Marker;
type YearNamesV1Marker = JapaneseYearNamesV1Marker;
type MonthNamesV1Marker = JapaneseMonthNamesV1Marker;
type SkeletaV1Marker = JapaneseDateNeoSkeletonPatternsV1Marker;
}

impl CldrCalendar for JapaneseExtended {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("japanext");
type DateSymbolsV1Marker = JapaneseExtendedDateSymbolsV1Marker;
type DateLengthsV1Marker = JapaneseExtendedDateLengthsV1Marker;
type YearNamesV1Marker = JapaneseExtendedYearNamesV1Marker;
type MonthNamesV1Marker = JapaneseExtendedMonthNamesV1Marker;
type SkeletaV1Marker = JapaneseExtendedDateNeoSkeletonPatternsV1Marker;
}

impl CldrCalendar for Persian {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("persian");
type DateSymbolsV1Marker = PersianDateSymbolsV1Marker;
type DateLengthsV1Marker = PersianDateLengthsV1Marker;
type YearNamesV1Marker = PersianYearNamesV1Marker;
type MonthNamesV1Marker = PersianMonthNamesV1Marker;
type SkeletaV1Marker = PersianDateNeoSkeletonPatternsV1Marker;
}

impl CldrCalendar for Roc {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("roc");
type DateSymbolsV1Marker = RocDateSymbolsV1Marker;
type DateLengthsV1Marker = RocDateLengthsV1Marker;
type YearNamesV1Marker = RocYearNamesV1Marker;
type MonthNamesV1Marker = RocMonthNamesV1Marker;
type SkeletaV1Marker = RocDateNeoSkeletonPatternsV1Marker;
Expand Down
93 changes: 0 additions & 93 deletions components/datetime/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,8 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::fields::Field;
use crate::fields::FieldSymbol;
use crate::pattern::PatternError;
use displaydoc::Display;
use icu_calendar::any_calendar::AnyCalendarKind;
use icu_calendar::types::MonthCode;
use icu_provider::DataError;

#[cfg(feature = "std")]
impl std::error::Error for DateTimeError {}

/// A list of error outcomes for various operations in this module.
#[derive(Display, Debug, Copy, Clone, PartialEq)]
#[non_exhaustive]
pub enum DateTimeError {
/// An error originating from parsing a pattern.
#[displaydoc("{0}")]
Pattern(PatternError),
/// An error originating from the [`Write`](std::fmt::Write) trait.
#[displaydoc("{0}")]
Format(core::fmt::Error),
/// An error originating inside of the [data provider](icu_provider).
#[displaydoc("{0}")]
Data(DataError),
/// An error originating from a missing field in datetime input.
/// TODO: How can we return which field was missing?
#[displaydoc("Missing input field")]
MissingInputField(Option<&'static str>),
/// An error originating from skeleton matching.
#[displaydoc("{0}")]
#[cfg(feature = "datagen")]
Skeleton(crate::skeleton::SkeletonError),
/// An error originating from an unsupported field in a datetime format.
#[displaydoc("Unsupported field: {0:?}")]
UnsupportedField(FieldSymbol),
/// An unsupported field with a field length.
// TODO(#2856): Consider renaming `UnsupportedField` to `UnsupportedFieldSymbol` so that
// this variant can be named `UnsupportedField`.
#[displaydoc("Unsupported field: {0:?}")]
UnsupportedFormattingField(Field),
/// An error due to there being no patterns for the given options.
#[displaydoc("Unsupported options")]
UnsupportedOptions,
/// An error originating from a missing weekday symbol in the data.
#[displaydoc("Data file missing weekday symbol for weekday {0}")]
MissingWeekdaySymbol(usize),
/// An error originating from a missing month symbol in the data.
#[displaydoc("Data file missing month symbol for month code {0}")]
MissingMonthSymbol(MonthCode),
/// The FixedDecimalFormatter is not loaded
#[displaydoc("Missing FixedDecimalFormatter")]
FixedDecimal,
/// An error from mixing calendar types in a formatter.
#[displaydoc("DateTimeFormatter for {0} calendar was given a {1:?} calendar")]
MismatchedAnyCalendar(AnyCalendarKind, Option<AnyCalendarKind>),
/// Missing date symbols
#[displaydoc("Missing date symbols")]
MissingDateSymbols,
/// Missing time symbols
#[displaydoc("Missing time symbols")]
MissingTimeSymbols,
/// ordinal_rules must be set for PatternPlurals::MultipleVariants
#[displaydoc("ordinal_rules must be set for PatternPlurals::MultipleVariants")]
MissingOrdinalRules,
/// The names for the given field are not loaded
#[displaydoc("Missing names for {0:?}")]
MissingNames(Field),
/// The same field occurs multiple times in a pattern or was loaded multiple times
#[displaydoc("Duplicate field: {0:?}")]
DuplicateField(Field),
}

/// An error from mixing calendar types in a formatter.
#[derive(Display, Debug, Copy, Clone, PartialEq)]
Expand All @@ -85,27 +16,3 @@ pub struct MismatchedCalendarError {
/// Can be `None` if the input calendar was not specified.
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<MismatchedCalendarError> for DateTimeError {
fn from(e: MismatchedCalendarError) -> Self {
DateTimeError::MismatchedAnyCalendar(e.this_kind, e.date_kind)
}
}
3 changes: 0 additions & 3 deletions components/datetime/src/format/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ pub enum DateTimeWriteError {
/// Missing weekday symbol
#[displaydoc("Cannot find symbol for weekday {0:?}")]
MissingWeekdaySymbol(IsoWeekday),
/// Missing time zone symbol
#[displaydoc("Not enough time zone information to format anything.")]
UnsupportedTimeZone,

// Invalid input
/// Incomplete input
Expand Down
Loading

0 comments on commit 987c364

Please sign in to comment.