Skip to content

Commit

Permalink
Move datetime::options::components to datetime::provider::skeleton::c…
Browse files Browse the repository at this point in the history
…omponents
  • Loading branch information
sffc committed Nov 13, 2024
1 parent 8d28584 commit 560e19a
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 65 deletions.
2 changes: 1 addition & 1 deletion components/datetime/benches/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use icu_datetime::{neo_skeleton, options::components};
use icu_datetime::{neo_skeleton, provider::skeleton::components};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down
3 changes: 0 additions & 3 deletions components/datetime/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

//! Options types for date/time formatting.
#[cfg(feature = "datagen")]
pub mod components;
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

//! 🚧 \[Experimental\] Options for constructing DateTimeFormatter objects by each component style.
//!
//! ✨ *Enabled with the `experimental` Cargo feature.*
//! Types for specifying fields in a classical datetime skeleton.
//!
//! <div class="stab unstable">
//! 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways,
Expand All @@ -13,45 +11,6 @@
//! <a href="https://github.com/unicode-org/icu4x/issues/1317">#1317</a>
//! </div>
//!
//! # Implementation status
//!
//! This module is available by enabling the `"experimental"` Cargo feature.
//! It may change in breaking ways, including across minor releases.
//!
//! This is currently only a partial implementation of the UTS-35 skeleton matching algorithm.
//!
//! | Algorithm step | Status |
//! |----------------|--------|
//! | Match skeleton fields according to a ranking | Implemented |
//! | Adjust the matched pattern to have certain widths | Implemented |
//! | Match date and times separately, and them combine them | Implemented |
//! | Use appendItems to fill in a pattern with missing fields | Not yet, and may not be fully implemented. See [issue #586](https://github.com/unicode-org/icu4x/issues/586) |
//!
//! # Description
//!
//! A [`components::Bag`](struct.Bag.html) is a model of encoding information on how to format date
//! and time by specifying a list of components the user wants to be visible in the formatted string
//! and how each field should be displayed.
//!
//! This model closely corresponds to `ECMA402` API and allows for high level of customization
//! compared to `Length` model.
//!
//! Additionally, the bag contains an optional set of `Preferences` which represent user
//! preferred adjustments that can be applied onto the pattern right before formatting.
//!
//! ## Pattern Selection
//!
//! The [`components::Bag`](struct.Bag.html) is a way for the developer to describe which components
//! should be included in in a datetime, and how they should be displayed. There is not a strict
//! guarantee in how the final date will be displayed to the end user. The user's preferences and
//! locale information can override the developer preferences.
//!
//! The fields in the [`components::Bag`](struct.Bag.html) are matched against available patterns in
//! the `CLDR` locale data. A best fit is found, and presented to the user. This means that in
//! certain situations, and component combinations, fields will not have a match, or the match will
//! have a different type of presentation for a given locale.
//!
//!
//! # Examples
//!
//! ```
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/provider/skeleton/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use alloc::vec;
use alloc::vec::Vec;
use core::cmp::Ordering;

use super::components;
use super::plural::PatternPlurals;
use crate::{
fields::{self, Field, FieldLength, FieldSymbol},
neo_skeleton::FractionalSecondDigits,
options::components,
provider::{
calendar::{
patterns::{FullLongMediumShort, GenericLengthPatternsV1},
Expand Down
40 changes: 39 additions & 1 deletion components/datetime/src/provider/skeleton/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,52 @@
//!
//! Semantic skeletons (field sets) use classical skeletons for pattern matching in datagen.
//!
//! See the [`Skeleton`](reference::Skeleton) struct for more information.
//! See [`Skeleton`](reference::Skeleton) and [`Bag`](components::Bag) for more information.
//!
//! ✨ *Enabled with the `datagen` Cargo feature.*
//!
//! # Implementation status
//!
//! This is currently only a partial implementation of the UTS-35 skeleton matching algorithm.
//!
//! | Algorithm step | Status |
//! |----------------|--------|
//! | Match skeleton fields according to a ranking | Implemented |
//! | Adjust the matched pattern to have certain widths | Implemented |
//! | Match date and times separately, and them combine them | Implemented |
//! | Use appendItems to fill in a pattern with missing fields | Not yet, and may not be fully implemented. See [issue #586](https://github.com/unicode-org/icu4x/issues/586) |
//!
//! # Description
//!
//! A [`components::Bag`](struct.Bag.html) is a model of encoding information on how to format date
//! and time by specifying a list of components the user wants to be visible in the formatted string
//! and how each field should be displayed.
//!
//! This model closely corresponds to `ECMA402` API and allows for high level of customization
//! compared to `Length` model.
//!
//! Additionally, the bag contains an optional set of `Preferences` which represent user
//! preferred adjustments that can be applied onto the pattern right before formatting.
//!
//! ## Pattern Selection
//!
//! The [`components::Bag`](struct.Bag.html) is a way for the developer to describe which components
//! should be included in in a datetime, and how they should be displayed. There is not a strict
//! guarantee in how the final date will be displayed to the end user. The user's preferences and
//! locale information can override the developer preferences.
//!
//! The fields in the [`components::Bag`](struct.Bag.html) are matched against available patterns in
//! the `CLDR` locale data. A best fit is found, and presented to the user. This means that in
//! certain situations, and component combinations, fields will not have a match, or the match will
//! have a different type of presentation for a given locale.
//!
//! <div class="stab unstable">
//! 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
//! including in SemVer minor releases. While the serde representation of data structs is guaranteed
//! to be stable, their Rust representation might not be. Use with caution.
//! </div>
pub mod components;
mod error;
mod helpers;
mod plural;
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/tests/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#![cfg(feature = "serde")]

use icu_datetime::{neo_skeleton, options::components};
use icu_datetime::{neo_skeleton, provider::skeleton::components};
use icu_locale_core::preferences::extensions::unicode::keywords::HourCycle;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/tests/resolved_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use icu_datetime::{
dynamic::{CompositeDateTimeFieldSet, DateAndTimeFieldSet, DateFieldSet, TimeFieldSet},
},
neo_skeleton::{Alignment, FractionalSecondDigits, TimePrecision, YearStyle},
options::components,
provider::skeleton::components,
FixedCalendarDateTimeFormatter,
};
use icu_locale_core::Locale;
Expand Down
11 changes: 4 additions & 7 deletions provider/source/src/datetime/neo_skeleton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ use crate::{IterableDataProviderCached, SourceDataProvider};
use either::Either;
use icu::datetime::fieldset::dynamic::*;
use icu::datetime::neo_skeleton::NeoSkeletonLength;
use icu::datetime::options::{components, preferences};
use icu::datetime::provider::calendar::{DateLengthsV1, DateSkeletonPatternsV1, TimeLengthsV1};
use icu::datetime::provider::pattern::runtime;
use icu::datetime::provider::skeleton::components;
use icu::datetime::provider::skeleton::PatternPlurals;
use icu::datetime::provider::*;
use icu::locale::extensions::unicode::{value, Value};
use icu::plurals::PluralElements;
use icu_locale_core::preferences::extensions::unicode::keywords::HourCycle;
use icu_provider::prelude::*;

use super::supported_cals;
Expand Down Expand Up @@ -302,14 +303,10 @@ fn gen_time_components(
filtered_components.hour = Some(components::Numeric::Numeric);
// Select the correct hour cycle
if check_for_field(attributes, "h") {
filtered_components.preferences = Some(preferences::Bag::from_hour_cycle(
preferences::HourCycle::H12,
));
filtered_components.hour_cycle = Some(HourCycle::H12);
}
if check_for_field(attributes, "h0") {
filtered_components.preferences = Some(preferences::Bag::from_hour_cycle(
preferences::HourCycle::H23,
));
filtered_components.hour_cycle = Some(HourCycle::H23);
}
filtered_components
}
Expand Down
16 changes: 8 additions & 8 deletions provider/source/src/datetime/skeletons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ mod test {
use icu::datetime::provider::skeleton::*;
use icu::datetime::{
fields::{Day, Field, FieldLength, Month, Weekday},
options::{components, preferences},
provider::calendar::{DateLengthsV1, DateSkeletonPatternsV1, SkeletonV1},
provider::pattern::{reference, runtime},
};
use icu::locale::locale;
use icu::locale::preferences::extensions::unicode::keywords::HourCycle;
use litemap::LiteMap;

use crate::SourceDataProvider;
Expand Down Expand Up @@ -117,7 +117,7 @@ mod test {
components.minute = Some(components::Numeric::Numeric);
components.second = Some(components::Numeric::Numeric);

let requested_fields = components.to_vec_fields(preferences::HourCycle::H23);
let requested_fields = components.to_vec_fields(HourCycle::H23);
let (_, skeletons) = get_data_payload();

match get_best_available_format_pattern(&skeletons, &requested_fields, false) {
Expand All @@ -142,7 +142,7 @@ mod test {
let mut components = components::Bag::empty();
components.time_zone_name = Some(components::TimeZoneName::LongOffset);
components.weekday = Some(components::Text::Short);
let requested_fields = components.to_vec_fields(preferences::HourCycle::H23);
let requested_fields = components.to_vec_fields(HourCycle::H23);
let (_, skeletons) = get_data_payload();

match get_best_available_format_pattern(&skeletons, &requested_fields, false) {
Expand Down Expand Up @@ -171,7 +171,7 @@ mod test {
components.day = Some(components::Day::NumericDayOfMonth);
// This will be appended.
components.time_zone_name = Some(components::TimeZoneName::LongSpecific);
let requested_fields = components.to_vec_fields(preferences::HourCycle::H23);
let requested_fields = components.to_vec_fields(HourCycle::H23);
let (patterns, skeletons) = get_data_payload();

match create_best_pattern_for_fields(
Expand All @@ -198,7 +198,7 @@ mod test {
#[test]
fn test_skeleton_empty_bag() {
let components: components::Bag = Default::default();
let requested_fields = components.to_vec_fields(preferences::HourCycle::H23);
let requested_fields = components.to_vec_fields(HourCycle::H23);
let (_, skeletons) = get_data_payload();

assert_eq!(
Expand All @@ -213,7 +213,7 @@ mod test {
let mut components = components::Bag::empty();
components.hour = Some(components::Numeric::Numeric);
components.time_zone_name = Some(components::TimeZoneName::LongSpecific);
let requested_fields = components.to_vec_fields(preferences::HourCycle::H23);
let requested_fields = components.to_vec_fields(HourCycle::H23);
// Construct a set of skeletons that do not use the hour nor time zone symbols.
let mut skeletons = LiteMap::new();
skeletons.insert(
Expand Down Expand Up @@ -370,7 +370,7 @@ mod test {
fn test_skeleton_matching_weekday_short() {
let mut components = components::Bag::empty();
components.weekday = Some(components::Text::Short);
let default_hour_cycle = preferences::HourCycle::H23;
let default_hour_cycle = HourCycle::H23;
let requested_fields = components.to_vec_fields(default_hour_cycle);
let (_, skeletons) = get_data_payload();

Expand All @@ -393,7 +393,7 @@ mod test {
fn test_skeleton_matching_weekday_long() {
let mut components = components::Bag::empty();
components.weekday = Some(components::Text::Long);
let default_hour_cycle = preferences::HourCycle::H23;
let default_hour_cycle = HourCycle::H23;
let requested_fields = components.to_vec_fields(default_hour_cycle);
let (_, skeletons) = get_data_payload();

Expand Down

0 comments on commit 560e19a

Please sign in to comment.