Skip to content

Commit

Permalink
Don't use 1.x baked data in icu_datetime (#5553)
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored Sep 18, 2024
1 parent 47ba490 commit b279bdc
Show file tree
Hide file tree
Showing 9 changed files with 564 additions and 749 deletions.
50 changes: 0 additions & 50 deletions components/datetime/src/format/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,56 +959,6 @@ mod tests {
);
}

#[test]
#[cfg(feature = "serde")]
fn test_basic() {
use crate::provider::calendar::{GregorianDateSymbolsV1Marker, TimeSymbolsV1Marker};
use icu_calendar::{Calendar, DateTime};
use icu_provider::prelude::*;

let locale = "en".parse().unwrap();
let req = DataRequest {
id: DataIdentifierBorrowed::for_locale(&locale),
..Default::default()
};
let date_data =
DataProvider::<GregorianDateSymbolsV1Marker>::load(&crate::provider::Baked, req)
.unwrap();
let time_data =
DataProvider::<TimeSymbolsV1Marker>::load(&crate::provider::Baked, req).unwrap();
let pattern: runtime::Pattern = "MMM".parse().unwrap();
let datetime = DateTime::try_new_gregorian_datetime(2020, 8, 1, 12, 34, 28).unwrap();
let fixed_decimal_format =
FixedDecimalFormatter::try_new(&locale, Default::default()).unwrap();

let mut sink = String::new();
try_write_pattern(
pattern.as_borrowed(),
&ExtractedInput {
year: Some(datetime.date.year()),
month: Some(datetime.date.month()),
day_of_month: Some(datetime.date.day_of_month()),
iso_weekday: Some(datetime.date.day_of_week()),
day_of_year_info: Some(datetime.date.day_of_year_info()),
any_calendar_kind: datetime.date.calendar().any_calendar_kind(),
hour: Some(datetime.time.hour),
minute: Some(datetime.time.minute),
second: Some(datetime.time.second),
nanosecond: Some(datetime.time.nanosecond),
..Default::default()
},
Some(date_data.payload.get()),
Some(time_data.payload.get()),
None::<()>.as_ref(),
None,
Some(&fixed_decimal_format),
&mut writeable::adapters::CoreWriteAsPartsWrite(&mut sink),
)
.unwrap()
.unwrap();
println!("{sink}");
}

#[test]
fn test_format_number() {
let values = &[2, 20, 201, 2017, 20173];
Expand Down
6 changes: 3 additions & 3 deletions components/datetime/src/options/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,16 @@ impl Bag {
}

#[allow(clippy::wrong_self_convention)]
/// Converts the components::Bag into a Vec<Field>. The fields will be ordered in from most
/// Converts the components::Bag into a `Vec<Field>`. The fields will be ordered in from most
/// significant field to least significant. This is the order the fields are listed in
/// the UTS 35 table - <https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table>
///
/// Arguments:
///
/// - `default_hour_cycle` specifies the hour cycle to use for the hour field if not in the Bag.
/// `preferences::Bag::hour_cycle` takes precedence over this argument.
#[cfg(any(test, feature = "datagen"))]
pub(crate) fn to_vec_fields(
#[cfg(feature = "datagen")]
pub fn to_vec_fields(
&self,
default_hour_cycle: preferences::HourCycle,
) -> alloc::vec::Vec<Field> {
Expand Down
35 changes: 1 addition & 34 deletions components/datetime/src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ pub mod neo;
/// </div>
pub struct Baked;

#[cfg(feature = "datagen")]
include!("../../tests/data/date_skeleton_patterns_v1_marker.rs.data");

#[cfg(feature = "compiled_data")]
#[allow(unused_imports)]
const _: () = {
Expand All @@ -46,44 +43,14 @@ const _: () = {
pub use icu_datetime_data::icu_locale as locale;
}
make_provider!(Baked);
impl_buddhist_date_lengths_v1_marker!(Baked);
impl_buddhist_date_symbols_v1_marker!(Baked);
impl_chinese_date_lengths_v1_marker!(Baked);
impl_chinese_date_symbols_v1_marker!(Baked);
impl_coptic_date_lengths_v1_marker!(Baked);
impl_coptic_date_symbols_v1_marker!(Baked);
impl_dangi_date_lengths_v1_marker!(Baked);
impl_dangi_date_symbols_v1_marker!(Baked);
impl_ethiopian_date_lengths_v1_marker!(Baked);
impl_ethiopian_date_symbols_v1_marker!(Baked);
impl_gregorian_date_lengths_v1_marker!(Baked);
impl_gregorian_date_symbols_v1_marker!(Baked);
impl_hebrew_date_lengths_v1_marker!(Baked);
impl_hebrew_date_symbols_v1_marker!(Baked);
impl_indian_date_lengths_v1_marker!(Baked);
impl_indian_date_symbols_v1_marker!(Baked);
impl_islamic_date_lengths_v1_marker!(Baked);
impl_islamic_date_symbols_v1_marker!(Baked);
impl_japanese_date_lengths_v1_marker!(Baked);
impl_japanese_date_symbols_v1_marker!(Baked);
impl_japanese_extended_date_lengths_v1_marker!(Baked);
impl_japanese_extended_date_symbols_v1_marker!(Baked);
impl_persian_date_lengths_v1_marker!(Baked);
impl_persian_date_symbols_v1_marker!(Baked);
impl_roc_date_lengths_v1_marker!(Baked);
impl_roc_date_symbols_v1_marker!(Baked);
impl_time_lengths_v1_marker!(Baked);
impl_time_symbols_v1_marker!(Baked);

impl_exemplar_cities_v1_marker!(Baked);
impl_metazone_generic_names_long_v1_marker!(Baked);
impl_metazone_generic_names_short_v1_marker!(Baked);
impl_metazone_specific_names_long_v1_marker!(Baked);
impl_metazone_specific_names_short_v1_marker!(Baked);
impl_time_zone_formats_v1_marker!(Baked);

#[cfg(feature = "datagen")]
impl_date_skeleton_patterns_v1_marker!(Baked);

impl_weekday_names_v1_marker!(Baked);
impl_day_period_names_v1_marker!(Baked);
impl_glue_pattern_v1_marker!(Baked);
Expand Down
163 changes: 0 additions & 163 deletions components/datetime/src/provider/neo/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,166 +450,3 @@ impl_data_provider_adapter!(
DayPeriodNamesV1Marker,
dayperiod_symbols_map_project_cloned
);

#[cfg(test)]
#[cfg(feature = "compiled_data")]
mod tests {
use super::*;
use icu_locale_core::langid;

#[test]
fn test_adapter_months_numeric() {
let symbols: DataPayload<GregorianDateSymbolsV1Marker> = crate::provider::Baked
.load(DataRequest {
id: DataIdentifierBorrowed::for_locale(&langid!("en").into()),
..Default::default()
})
.unwrap()
.payload;
let neo_month_abbreviated: DataPayload<GregorianMonthNamesV1Marker> = symbols
.load(DataRequest {
id: DataIdentifierBorrowed::for_marker_attributes_and_locale(
DataMarkerAttributes::from_str_or_panic("3"),
&"en".parse().unwrap(),
),
..Default::default()
})
.unwrap()
.payload;

assert_eq!(
format!("{neo_month_abbreviated:?}"),
"Linear([\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"])"
);
}

#[test]
fn test_adapter_months_map() {
let symbols: DataPayload<HebrewDateSymbolsV1Marker> = crate::provider::Baked
.load(DataRequest {
id: DataIdentifierBorrowed::for_locale(&langid!("en").into()),
..Default::default()
})
.unwrap()
.payload;
let neo_month_abbreviated: DataPayload<HebrewMonthNamesV1Marker> = symbols
.load(DataRequest {
id: DataIdentifierBorrowed::for_marker_attributes_and_locale(
DataMarkerAttributes::from_str_or_panic("3"),
&"en".parse().unwrap(),
),
..Default::default()
})
.unwrap()
.payload;

assert_eq!(
format!("{neo_month_abbreviated:?}"),
"LeapLinear([\"Tishri\", \"Heshvan\", \"Kislev\", \"Tevet\", \"Shevat\", \"Adar\", \"Nisan\", \"Iyar\", \"Sivan\", \"Tamuz\", \"Av\", \"Elul\", \"\", \"\", \"\", \"\", \"Adar I\", \"Adar II\", \"\", \"\", \"\", \"\", \"\", \"\"])"
);
}

#[test]
fn test_adapter_weekdays_abbreviated() {
let symbols: DataPayload<HebrewDateSymbolsV1Marker> = crate::provider::Baked
.load(DataRequest {
id: DataIdentifierBorrowed::for_locale(&langid!("en").into()),
..Default::default()
})
.unwrap()
.payload;
let neo_weekdays_abbreviated: DataPayload<WeekdayNamesV1Marker> = symbols
.load(DataRequest {
id: DataIdentifierBorrowed::for_marker_attributes_and_locale(
DataMarkerAttributes::from_str_or_panic("3"),
&"en".parse().unwrap(),
),
..Default::default()
})
.unwrap()
.payload;

assert_eq!(
format!("{neo_weekdays_abbreviated:?}"),
"LinearNamesV1 { symbols: [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"] }"
);
}

#[test]
fn test_adapter_weekdays_short() {
let symbols: DataPayload<HebrewDateSymbolsV1Marker> = crate::provider::Baked
.load(DataRequest {
id: DataIdentifierBorrowed::for_locale(&langid!("en").into()),
..Default::default()
})
.unwrap()
.payload;
let neo_weekdays_short: DataPayload<WeekdayNamesV1Marker> = symbols
.load(DataRequest {
id: DataIdentifierBorrowed::for_marker_attributes_and_locale(
DataMarkerAttributes::from_str_or_panic("6s"),
&"en".parse().unwrap(),
),
..Default::default()
})
.unwrap()
.payload;

assert_eq!(
format!("{neo_weekdays_short:?}"),
"LinearNamesV1 { symbols: [\"Su\", \"Mo\", \"Tu\", \"We\", \"Th\", \"Fr\", \"Sa\"] }"
);
}

#[test]
fn test_adapter_eras() {
let symbols: DataPayload<GregorianDateSymbolsV1Marker> = crate::provider::Baked
.load(DataRequest {
id: DataIdentifierBorrowed::for_locale(&langid!("en").into()),
..Default::default()
})
.unwrap()
.payload;
let neo_eras_wide: DataPayload<GregorianYearNamesV1Marker> = symbols
.load(DataRequest {
id: DataIdentifierBorrowed::for_marker_attributes_and_locale(
DataMarkerAttributes::from_str_or_panic("4"),
&"en".parse().unwrap(),
),
..Default::default()
})
.unwrap()
.payload;

assert_eq!(
format!("{neo_eras_wide:?}"),
"Eras(ZeroMap { keys: [\"bce\", \"ce\"], values: [\"Before Christ\", \"Anno Domini\"] })"
);
}

#[test]
fn test_adapter_dayperiods() {
let symbols: DataPayload<TimeSymbolsV1Marker> = crate::provider::Baked
.load(DataRequest {
id: DataIdentifierBorrowed::for_locale(&langid!("en").into()),
..Default::default()
})
.unwrap()
.payload;
let neo_dayperiods_abbreviated: DataPayload<DayPeriodNamesV1Marker> = symbols
.load(DataRequest {
id: DataIdentifierBorrowed::for_marker_attributes_and_locale(
DataMarkerAttributes::from_str_or_panic("3s"),
&"en".parse().unwrap(),
),
..Default::default()
})
.unwrap()
.payload;

assert_eq!(
format!("{neo_dayperiods_abbreviated:?}"),
"LinearNamesV1 { symbols: [\"AM\", \"PM\", \"noon\", \"midnight\"] }"
);
}
}
Loading

0 comments on commit b279bdc

Please sign in to comment.