Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NeoSkeletonLength -> Length #5846

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ icu = "1.5.0"

```rust
use icu::calendar::DateTime;
use icu::datetime::{DateTimeFormatter, NeoSkeletonLength, fieldsets::YMDT};
use icu::datetime::{DateTimeFormatter, Length, fieldsets::YMDT};
use icu::locale::locale;

let dtf = DateTimeFormatter::try_new(
Expand Down
7 changes: 2 additions & 5 deletions components/datetime/src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

use crate::raw::neo::RawOptions;
use crate::scaffold::GetField;
use crate::{fields, fieldsets, NeoSkeletonLength};
use crate::{fields, fieldsets, Length};
use icu_provider::prelude::*;

/// An enumeration over all possible date field sets.
Expand Down Expand Up @@ -470,10 +470,7 @@ impl_attrs! {
}

impl ZoneFieldSet {
pub(crate) fn from_time_zone_style_and_length(
style: ZoneStyle,
length: NeoSkeletonLength,
) -> Self {
pub(crate) fn from_time_zone_style_and_length(style: ZoneStyle, length: Length) -> Self {
match style {
ZoneStyle::Z => Self::Z(fieldsets::Z::with_length(length)),
ZoneStyle::O => Self::O(fieldsets::O::with_length(length)),
Expand Down
16 changes: 8 additions & 8 deletions components/datetime/src/fieldsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ macro_rules! impl_marker_with_options {
$(
/// The desired length of the formatted string.
///
/// See: [`NeoSkeletonLength`]
/// See: [`Length`]
pub length: datetime_marker_helper!(@option/length, $sample_length),
)?
$(
Expand All @@ -162,7 +162,7 @@ macro_rules! impl_marker_with_options {
}
impl $type {
#[doc = concat!("Creates a ", stringify!($type), " skeleton with the given formatting length.")]
pub const fn with_length(length: NeoSkeletonLength) -> Self {
pub const fn with_length(length: Length) -> Self {
Self {
length,
$(
Expand All @@ -178,15 +178,15 @@ macro_rules! impl_marker_with_options {
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a long length.")]
pub const fn long() -> Self {
Self::with_length(NeoSkeletonLength::Long)
Self::with_length(Length::Long)
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a medium length.")]
pub const fn medium() -> Self {
Self::with_length(NeoSkeletonLength::Medium)
Self::with_length(Length::Medium)
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a short length.")]
pub const fn short() -> Self {
Self::with_length(NeoSkeletonLength::Short)
Self::with_length(Length::Short)
}
}
#[allow(dead_code)]
Expand Down Expand Up @@ -266,7 +266,7 @@ macro_rules! impl_combo_generic_fns {
($type:ident) => {
impl<Z> Combo<$type, Z> {
#[doc = concat!("Creates a ", stringify!($type), " skeleton with the given formatting length and a time zone.")]
pub fn with_length(length: NeoSkeletonLength) -> Self {
pub fn with_length(length: Length) -> Self {
Self::new($type::with_length(length))
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a long length and a time zone.")]
Expand Down Expand Up @@ -881,8 +881,8 @@ macro_rules! impl_zone_marker {
impl $type {
pub(crate) fn to_field(self) -> (fields::TimeZone, fields::FieldLength) {
match self.length {
NeoSkeletonLength::Short | NeoSkeletonLength::Medium => $field_short,
NeoSkeletonLength::Long => $field_long,
Length::Short | Length::Medium => $field_short,
Length::Long => $field_long,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ pub use neo::DateTimeFormatterPreferences;
pub use neo::FixedCalendarDateTimeFormatter;
pub use neo::FormattedDateTime;
pub use neo::TimeFormatter;
pub use options::NeoSkeletonLength;
pub use options::Length;
4 changes: 2 additions & 2 deletions components/datetime/src/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ where
///
/// let formatter = DateTimeFormatter::try_new(
/// locale!("es-MX").into(),
/// NeoSkeletonLength::Long.into(),
/// Length::Long.into(),
/// )
/// .unwrap();
///
Expand Down Expand Up @@ -614,7 +614,7 @@ where
///
/// let formatter = DateTimeFormatter::try_new(
/// locale!("es-MX").into(),
/// NeoSkeletonLength::Long.into(),
/// Length::Long.into(),
/// )
/// .unwrap();
///
Expand Down
4 changes: 2 additions & 2 deletions components/datetime/src/neo_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub enum CompositeFieldSetSerdeError {
pub struct CompositeFieldSetSerde {
#[serde(rename = "fieldSet")]
pub(crate) field_set: FieldSetSerde,
pub(crate) length: NeoSkeletonLength,
pub(crate) length: Length,
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) alignment: Option<Alignment>,
#[serde(rename = "yearStyle")]
Expand Down Expand Up @@ -567,7 +567,7 @@ impl FieldSetSerde {
fn test_basic() {
let skeleton = CompositeFieldSet::DateTimeZone(
DateAndTimeFieldSet::YMDET(fieldsets::YMDET {
length: NeoSkeletonLength::Medium,
length: Length::Medium,
alignment: Some(Alignment::Column),
year_style: Some(YearStyle::Always),
time_precision: Some(TimePrecision::SecondExact(FractionalSecondDigits::F3)),
Expand Down
4 changes: 2 additions & 2 deletions components/datetime/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ use crate::neo_serde::TimePrecisionSerde;
)]
#[repr(u8)] // discriminants come from symbol count in UTS 35
#[non_exhaustive]
pub enum NeoSkeletonLength {
pub enum Length {
/// A long date; typically spelled-out, as in “January 1, 2000”.
Long = 4,
/// A medium-sized date; typically abbreviated, as in “Jan. 1, 2000”.
Expand All @@ -81,7 +81,7 @@ pub enum NeoSkeletonLength {
Short = 1,
}

impl IntoOption<NeoSkeletonLength> for NeoSkeletonLength {
impl IntoOption<Length> for Length {
#[inline]
fn into_option(self) -> Option<Self> {
Some(self)
Expand Down
4 changes: 2 additions & 2 deletions components/datetime/src/provider/neo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ pub mod marker_attrs {

/// Pattern lengths supported in data marker attributes.
///
/// For a stable version of this enum, use [`NeoSkeletonLength`].
/// For a stable version of this enum, use [`Length`].
///
/// <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>
///
/// [`NeoSkeletonLength`]: crate::options::NeoSkeletonLength
/// [`Length`]: crate::options::Length
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum PatternLength {
Long,
Expand Down
14 changes: 5 additions & 9 deletions components/datetime/src/provider/packed_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::pattern::{
runtime::{Pattern, PatternBorrowed, PatternMetadata},
PatternItem,
};
use crate::{size_test_macro::size_test, NeoSkeletonLength};
use crate::{size_test_macro::size_test, Length};
use alloc::vec::Vec;
use icu_plurals::{
provider::{FourBitMetadata, PluralElementsPackedULE},
Expand Down Expand Up @@ -407,12 +407,8 @@ pub(crate) enum PackedSkeletonVariant {
}

impl PackedPatternsV1<'_> {
pub(crate) fn get(
&self,
length: NeoSkeletonLength,
variant: PackedSkeletonVariant,
) -> PatternBorrowed {
use NeoSkeletonLength::*;
pub(crate) fn get(&self, length: Length, variant: PackedSkeletonVariant) -> PatternBorrowed {
use Length::*;
use PackedSkeletonVariant::*;
let lms = self.header & constants::LMS_MASK;
let pattern_index = if matches!(variant, Standard) {
Expand Down Expand Up @@ -482,15 +478,15 @@ impl PackedPatternsV1<'_> {

fn get_as_plural_elements(
&self,
length: NeoSkeletonLength,
length: Length,
variant: PackedSkeletonVariant,
) -> PluralElements<Pattern> {
PluralElements::new(self.get(length, variant).as_pattern())
}

/// Converts this packed data to a builder that can be mutated.
pub fn to_builder(&self) -> PackedPatternsBuilder {
use NeoSkeletonLength::*;
use Length::*;
use PackedSkeletonVariant::*;
let mut builder = PackedPatternsBuilder {
standard: LengthPluralElements {
Expand Down
26 changes: 10 additions & 16 deletions components/datetime/src/raw/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use zerovec::ZeroSlice;

#[derive(Debug, Copy, Clone)]
pub(crate) struct RawOptions {
pub(crate) length: NeoSkeletonLength,
pub(crate) length: Length,
pub(crate) alignment: Option<Alignment>,
pub(crate) year_style: Option<YearStyle>,
pub(crate) time_precision: Option<TimePrecision>,
Expand Down Expand Up @@ -575,10 +575,8 @@ impl DateTimeZonePatternSelectionData {
options,
)?;
// Always use the short length for time zones when mixed with another field (Date)
let zone_field_set = ZoneFieldSet::from_time_zone_style_and_length(
time_zone_style,
NeoSkeletonLength::Short,
);
let zone_field_set =
ZoneFieldSet::from_time_zone_style_and_length(time_zone_style, Length::Short);
let zone = ZonePatternSelectionData::new_with_skeleton(zone_field_set);
let glue = Self::load_glue(glue_provider, prefs, options, GlueType::DateZone)?;
Ok(Self::DateZoneGlue { date, zone, glue })
Expand All @@ -592,10 +590,8 @@ impl DateTimeZonePatternSelectionData {
options,
)?;
// Always use the short length for time zones when mixed with another field (Time)
let zone_field_set = ZoneFieldSet::from_time_zone_style_and_length(
time_zone_style,
NeoSkeletonLength::Short,
);
let zone_field_set =
ZoneFieldSet::from_time_zone_style_and_length(time_zone_style, Length::Short);
let zone = ZonePatternSelectionData::new_with_skeleton(zone_field_set);
let glue = Self::load_glue(glue_provider, prefs, options, GlueType::TimeZone)?;
Ok(Self::TimeZoneGlue { time, zone, glue })
Expand All @@ -615,10 +611,8 @@ impl DateTimeZonePatternSelectionData {
options,
)?;
// Always use the short length for time zones when mixed with another field (Date + Time)
let zone_field_set = ZoneFieldSet::from_time_zone_style_and_length(
time_zone_style,
NeoSkeletonLength::Short,
);
let zone_field_set =
ZoneFieldSet::from_time_zone_style_and_length(time_zone_style, Length::Short);
let zone = ZonePatternSelectionData::new_with_skeleton(zone_field_set);
let glue = Self::load_glue(glue_provider, prefs, options, GlueType::DateTimeZone)?;
Ok(Self::DateTimeZoneGlue {
Expand All @@ -645,9 +639,9 @@ impl DateTimeZonePatternSelectionData {
// According to UTS 35, use the date length here: use the glue
// pattern "whose type matches the type of the date pattern"
match options.length {
NeoSkeletonLength::Long => marker_attrs::PatternLength::Long,
NeoSkeletonLength::Medium => marker_attrs::PatternLength::Medium,
NeoSkeletonLength::Short => marker_attrs::PatternLength::Short,
Length::Long => marker_attrs::PatternLength::Long,
Length::Medium => marker_attrs::PatternLength::Medium,
Length::Short => marker_attrs::PatternLength::Short,
},
glue_type,
),
Expand Down
8 changes: 4 additions & 4 deletions components/datetime/src/scaffold/fieldset_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,16 +499,16 @@ macro_rules! datetime_marker_helper {
NeverMarker<GluePatternV1<'static>>
};
(@option/length, yes) => {
NeoSkeletonLength
Length
};
(@option/length, long) => {
NeoSkeletonLength
Length
};
(@option/length, medium) => {
NeoSkeletonLength
Length
};
(@option/length, short) => {
NeoSkeletonLength
Length
};
(@option/yearstyle, yes) => {
Option<YearStyle>
Expand Down
16 changes: 8 additions & 8 deletions components/datetime/tests/patterns/time_zones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use icu_datetime::{
fieldsets::{self, enums::ZoneFieldSet},
options::NeoSkeletonLength,
options::Length,
};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
Expand All @@ -21,13 +21,13 @@ pub struct TimeZoneTest {

pub fn pattern_to_semantic_skeleton(p: &str) -> Option<ZoneFieldSet> {
Some(match p {
"vvvv" => ZoneFieldSet::V(fieldsets::V::with_length(NeoSkeletonLength::Long)),
"v" => ZoneFieldSet::V(fieldsets::V::with_length(NeoSkeletonLength::Short)),
"VVVV" => ZoneFieldSet::L(fieldsets::L::with_length(NeoSkeletonLength::Long)),
"zzzz" => ZoneFieldSet::Z(fieldsets::Z::with_length(NeoSkeletonLength::Long)),
"z" => ZoneFieldSet::Z(fieldsets::Z::with_length(NeoSkeletonLength::Short)),
"OOOO" => ZoneFieldSet::O(fieldsets::O::with_length(NeoSkeletonLength::Long)),
"O" => ZoneFieldSet::O(fieldsets::O::with_length(NeoSkeletonLength::Short)),
"vvvv" => ZoneFieldSet::V(fieldsets::V::with_length(Length::Long)),
"v" => ZoneFieldSet::V(fieldsets::V::with_length(Length::Short)),
"VVVV" => ZoneFieldSet::L(fieldsets::L::with_length(Length::Long)),
"zzzz" => ZoneFieldSet::Z(fieldsets::Z::with_length(Length::Long)),
"z" => ZoneFieldSet::Z(fieldsets::Z::with_length(Length::Short)),
"OOOO" => ZoneFieldSet::O(fieldsets::O::with_length(Length::Long)),
"O" => ZoneFieldSet::O(fieldsets::O::with_length(Length::Short)),
_ => return None,
})
}
4 changes: 2 additions & 2 deletions components/icu/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/icu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//! Compiled data is exposed through idiomatic Rust constructors like `new` or `try_new`:
//!
//! ```
//! use icu::datetime::{DateTimeFormatter, NeoSkeletonLength, fieldsets::YMD};
//! use icu::datetime::{DateTimeFormatter, Length, fieldsets::YMD};
//! use icu::locale::locale;
//!
//! let dtf = DateTimeFormatter::try_new(
Expand All @@ -51,7 +51,7 @@
//! special constructors:
//!
//! ```no_run
//! use icu::datetime::{DateTimeFormatter, NeoSkeletonLength, fieldsets::YMD};
//! use icu::datetime::{DateTimeFormatter, Length, fieldsets::YMD};
//! use icu::locale::locale;
//! use icu::locale::fallback::LocaleFallbacker;
//! use icu_provider_adapters::fallback::LocaleFallbackProvider;
Expand Down
2 changes: 1 addition & 1 deletion ffi/capi/bindings/dart/DateTimeLength.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ffi/capi/bindings/js/DateTimeLength.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ffi/capi/bindings/js/DateTimeLength.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading