Skip to content

Commit 1262ac1

Browse files
authored
Suppress conflicting datetime fields in datagen (#6477)
Fixes #6205
1 parent 611c3da commit 1262ac1

File tree

219 files changed

+1190
-997
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+1190
-997
lines changed

components/datetime/src/pattern/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod names;
1515
#[allow(clippy::module_inception)] // the file pattern.rs should contain DateTimePattern
1616
mod pattern;
1717

18-
use crate::error::ErrorField;
18+
pub use crate::error::ErrorField;
1919
pub use formatter::DateTimePatternFormatter;
2020
pub use formatter::FormattedDateTimePattern;
2121
use icu_pattern::SinglePlaceholderPattern;

components/datetime/src/pattern/pattern.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ impl DateTimePattern {
115115
Ok(Self { pattern })
116116
}
117117

118-
#[doc(hidden)] // TODO(#4467): Internal API
119-
pub fn from_runtime_pattern(pattern: runtime::Pattern<'static>) -> Self {
120-
Self { pattern }
121-
}
122-
123118
pub(crate) fn iter_items(&self) -> impl Iterator<Item = PatternItem> + '_ {
124119
self.pattern.items.iter()
125120
}
@@ -129,6 +124,28 @@ impl DateTimePattern {
129124
}
130125
}
131126

127+
impl<'a> From<runtime::Pattern<'a>> for DateTimePattern {
128+
fn from(pattern: runtime::Pattern<'a>) -> Self {
129+
Self {
130+
pattern: pattern.into_owned(),
131+
}
132+
}
133+
}
134+
135+
impl<'a> From<runtime::PatternBorrowed<'a>> for DateTimePattern {
136+
fn from(pattern: runtime::PatternBorrowed<'a>) -> Self {
137+
Self {
138+
pattern: pattern.as_pattern().into_owned(),
139+
}
140+
}
141+
}
142+
143+
impl From<DateTimePattern> for runtime::Pattern<'_> {
144+
fn from(value: DateTimePattern) -> Self {
145+
value.pattern
146+
}
147+
}
148+
132149
impl FromStr for DateTimePattern {
133150
type Err = PatternError;
134151
fn from_str(s: &str) -> Result<Self, Self::Err> {

components/datetime/src/provider/fields/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub(crate) mod symbols;
1212
use displaydoc::Display;
1313
pub use length::{FieldLength, FieldNumericOverrides, LengthError};
1414
pub use symbols::*;
15+
use writeable::Writeable;
1516

1617
#[cfg(any(feature = "experimental", feature = "datagen"))]
1718
pub mod components;
@@ -77,6 +78,21 @@ impl Field {
7778
}
7879
}
7980

81+
impl Writeable for Field {
82+
fn write_to<W: core::fmt::Write + ?Sized>(&self, sink: &mut W) -> core::fmt::Result {
83+
let ch: char = self.symbol.into();
84+
for _ in 0..self.length.to_len() {
85+
sink.write_char(ch)?;
86+
}
87+
Ok(())
88+
}
89+
fn writeable_length_hint(&self) -> writeable::LengthHint {
90+
writeable::LengthHint::exact(self.length.to_len())
91+
}
92+
}
93+
94+
writeable::impl_display_with_writeable!(Field);
95+
8096
impl FieldULE {
8197
#[inline]
8298
pub(crate) fn validate_byte_pair(bytes: (u8, u8)) -> Result<(), zerovec::ule::UleError> {

components/datetime/src/provider/pattern/runtime/display.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ impl Writeable for Pattern<'_> {
7777
PatternItem::Field(field) => {
7878
dump_buffer_into_formatter(&buffer, formatter)?;
7979
buffer.clear();
80-
let ch: char = field.symbol.into();
81-
for _ in 0..field.length.to_len() {
82-
formatter.write_char(ch)?;
83-
}
80+
field.write_to(formatter)?;
8481
if let FieldSymbol::DecimalSecond(decimal_second) = field.symbol {
8582
formatter.write_char('.')?;
8683
for _ in 0..(decimal_second as u8) {

components/datetime/src/provider/pattern/runtime/pattern.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ impl Default for PatternMetadata {
116116
}
117117

118118
impl Pattern<'_> {
119-
#[cfg(feature = "datagen")]
120119
pub(crate) fn into_owned(self) -> Pattern<'static> {
121120
Pattern {
122121
items: self.items.into_owned(),

components/datetime/src/provider/skeleton/helpers.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ impl SkeletonQuality {
114114
pub fn best() -> SkeletonQuality {
115115
SkeletonQuality(0)
116116
}
117+
/// Returns whether this is an "excellent" match by an arbitrary definition.
118+
pub fn is_excellent_match(self) -> bool {
119+
self.0 < GLUE_DISTANCE
120+
}
117121
}
118122

119123
/// This function swaps out the time zone name field for the appropriate one. Skeleton matching

components/datetime/src/raw/neo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ impl<'a> DateTimeZonePatternDataBorrowed<'a> {
734734

735735
pub(crate) fn to_pattern(self) -> DateTimePattern {
736736
let pattern = self.iter_items().collect::<runtime::Pattern>();
737-
DateTimePattern::from_runtime_pattern(pattern)
737+
DateTimePattern::from(pattern)
738738
}
739739
}
740740

components/decimal/src/provider.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ impl DecimalSymbols<'_> {
296296
}
297297

298298
impl DecimalSymbols<'static> {
299-
#[cfg(test)]
300299
/// Create a new en-US format for use in testing
301-
pub(crate) fn new_en_for_testing() -> Self {
300+
#[cfg(feature = "datagen")]
301+
pub fn new_en_for_testing() -> Self {
302302
let strings = DecimalSymbolStrsBuilder {
303303
minus_sign_prefix: VarZeroCow::new_borrowed("-"),
304304
minus_sign_suffix: VarZeroCow::new_borrowed(""),

provider/data/datetime/data/datetime_patterns_date_buddhist_v1.rs.data

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provider/data/datetime/data/datetime_patterns_date_chinese_v1.rs.data

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)