-
Notifications
You must be signed in to change notification settings - Fork 182
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
Create TypedNeoDateTimeFormatter and DateTimePattern types #4415
Merged
+2,071
−213
Merged
Changes from all commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
36cb3f3
Create PatternMetadata
sffc bd3c7d5
Add make_varule
sffc 44974a9
Add more feature = "compiled_data" to tests so we can build without it
sffc 5b64137
More compiled_data guards
sffc ca39084
Add databake and serde support for PatternMetadata
sffc bb6d8ea
cargo make bakeddata
sffc 05ff2cb
fmt
sffc fdbe0d5
docs
sffc 3a3d177
Initial shape of DateTimePattern
sffc 0ca62f8
Add CldrCalendar::DatePatternV1Marker
sffc 694ca69
Add data loading for date pattern to TypedDateTimePattern
sffc f4a8899
rm unnecessary ErasedTimePatternV1Marker
sffc 43f03f1
Initial RawNeoDateTimeFormatter data model
sffc 8e20b31
Experimentation
sffc 6f49ba1
More types and things
sffc e294168
New top-level neo module
sffc 65942a3
Don't take a position yet on Copy/Clone
sffc 032c6bb
Big chunk of work
sffc fa8cedb
End-to-end test passing
sffc bf58bd9
Prettify docs
sffc eb8774b
Add DateTime::local_unix_epoch
sffc 6e96e69
FormattedNeoDateTime::pattern() working
sffc 47a9bc3
Move DateTimePattern to a different place
sffc 78a0832
Use public DateTimePattern API
sffc 67f3c3e
Merge branch 'main' into neo3
sffc 6a6ee0c
Add time end-to-end
sffc 06cad34
DateTime checkpoint
sffc 9859fd9
Next datetime checkpoint
sffc 3d8bf91
First NeoDateTime end-to-end test with glue working
sffc c0e9df4
Cleanups
sffc d5fb9a2
Implement TypedNeoDateFormatter
sffc 0df175d
Merge impls
sffc 2e6a9cd
Implement TypedNeoTimeFormatter; fmt docs
sffc 6832da2
Fix features and imports
sffc 958017c
Remove type parameter from NeoTimeFormatter
sffc 285e28f
Fix neo weekday bug
sffc 24046f5
Hack to workaround #4412
sffc 740e4b1
Add DateTimeFormatterOptions API
sffc 7127e3a
Add to benches
sffc 66ec6a3
Start adding another test
sffc 30efbf9
Merge remote-tracking branch 'upstream/main' into neo3
sffc b540af9
Reset data to upstream version
sffc 6ca166f
Try again, syncing with upstream
sffc 7368623
Fix datetime ordering; more testing
sffc ea248d3
Merge branch 'main' into neo3
sffc 7dff39a
Clippy
sffc 7b3ccaa
More tests
sffc b518c6b
Minor cleanup. Delete sizes test
sffc c476eec
Add buffer/any/unstable constructors for NeoDateFormatter
sffc 97bf45f
fmt
sffc 2841c40
Refactoring of loader traits
sffc 1d39d51
Refactor external loading further
sffc 1d84481
Refactor external loaders further and merge into single type
sffc d2acdee
Split loader argument again, make week calculator optional, and imple…
sffc 7d0139e
Refactor external loader: move locale to function
sffc 9a0862e
Implement for try_new_with_date_length
sffc 52a09e5
Use a macro for any/buffer constructors
sffc 8123348
try_new_with_time_length_internal
sffc 0f16e6b
try_new_with_lengths_internal
sffc b45259f
features
sffc f6361f5
fmt
sffc 59e0b4d
Bug fix
sffc 790a70e
Docs fix
sffc d389581
Merge branch 'main' into neo3
sffc 590672d
try_from_pattern_str docs
sffc b72f174
Merge remote-tracking branch 'upstream/main' into neo3
sffc 451272d
diplomat coverage
sffc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// This file is part of ICU4X. For terms of use, please see the file | ||
// called LICENSE at the top level of the ICU4X source tree | ||
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). | ||
|
||
//! Internal traits and structs for loading data from other crates. | ||
|
||
use icu_calendar::provider::WeekDataV2Marker; | ||
use icu_calendar::week::WeekCalculator; | ||
use icu_calendar::CalendarError; | ||
use icu_decimal::options::FixedDecimalFormatterOptions; | ||
use icu_decimal::provider::DecimalSymbolsV1Marker; | ||
use icu_decimal::{DecimalError, FixedDecimalFormatter}; | ||
use icu_provider::prelude::*; | ||
|
||
/// Trait for loading a FixedDecimalFormatter. | ||
/// | ||
/// Implemented on the provider-specific loader types in this module. | ||
pub(crate) trait FixedDecimalFormatterLoader { | ||
fn load( | ||
&self, | ||
locale: &DataLocale, | ||
options: FixedDecimalFormatterOptions, | ||
) -> Result<FixedDecimalFormatter, DecimalError>; | ||
} | ||
|
||
/// Trait for loading a WeekCalculator. | ||
/// | ||
/// Implemented on the provider-specific loader types in this module. | ||
pub(crate) trait WeekCalculatorLoader { | ||
fn load(&self, locale: &DataLocale) -> Result<WeekCalculator, CalendarError>; | ||
} | ||
|
||
/// Helper for type resolution with optional loader arguments | ||
pub(crate) struct PhantomLoader { | ||
_not_constructible: core::convert::Infallible, | ||
} | ||
|
||
impl FixedDecimalFormatterLoader for PhantomLoader { | ||
fn load( | ||
&self, | ||
_locale: &DataLocale, | ||
_options: FixedDecimalFormatterOptions, | ||
) -> Result<FixedDecimalFormatter, DecimalError> { | ||
unreachable!() // not constructible | ||
} | ||
} | ||
|
||
impl WeekCalculatorLoader for PhantomLoader { | ||
#[inline] | ||
fn load(&self, _locale: &DataLocale) -> Result<WeekCalculator, CalendarError> { | ||
unreachable!() // not constructible | ||
} | ||
} | ||
|
||
/// Loader for types from other crates using compiled data. | ||
#[cfg(feature = "compiled_data")] | ||
pub(crate) struct ExternalLoaderCompiledData; | ||
|
||
#[cfg(feature = "compiled_data")] | ||
impl FixedDecimalFormatterLoader for ExternalLoaderCompiledData { | ||
#[inline] | ||
fn load( | ||
&self, | ||
locale: &DataLocale, | ||
options: FixedDecimalFormatterOptions, | ||
) -> Result<FixedDecimalFormatter, DecimalError> { | ||
FixedDecimalFormatter::try_new(locale, options) | ||
} | ||
} | ||
|
||
#[cfg(feature = "compiled_data")] | ||
impl WeekCalculatorLoader for ExternalLoaderCompiledData { | ||
#[inline] | ||
fn load(&self, locale: &DataLocale) -> Result<WeekCalculator, CalendarError> { | ||
WeekCalculator::try_new(locale) | ||
} | ||
} | ||
|
||
/// Loader for types from other crates using [`AnyProvider`]. | ||
pub(crate) struct ExternalLoaderAny<'a, P: ?Sized>(pub &'a P); | ||
|
||
impl<P> FixedDecimalFormatterLoader for ExternalLoaderAny<'_, P> | ||
where | ||
P: ?Sized + AnyProvider, | ||
{ | ||
#[inline] | ||
fn load( | ||
&self, | ||
locale: &DataLocale, | ||
options: FixedDecimalFormatterOptions, | ||
) -> Result<FixedDecimalFormatter, DecimalError> { | ||
FixedDecimalFormatter::try_new_with_any_provider(self.0, locale, options) | ||
} | ||
} | ||
|
||
impl<P> WeekCalculatorLoader for ExternalLoaderAny<'_, P> | ||
where | ||
P: ?Sized + AnyProvider, | ||
{ | ||
#[inline] | ||
fn load(&self, locale: &DataLocale) -> Result<WeekCalculator, CalendarError> { | ||
WeekCalculator::try_new_with_any_provider(self.0, locale) | ||
} | ||
} | ||
|
||
/// Loader for types from other crates using [`BufferProvider`]. | ||
#[cfg(feature = "serde")] | ||
pub(crate) struct ExternalLoaderBuffer<'a, P: ?Sized>(pub &'a P); | ||
|
||
#[cfg(feature = "serde")] | ||
impl<P> FixedDecimalFormatterLoader for ExternalLoaderBuffer<'_, P> | ||
where | ||
P: ?Sized + BufferProvider, | ||
{ | ||
#[inline] | ||
fn load( | ||
&self, | ||
locale: &DataLocale, | ||
options: FixedDecimalFormatterOptions, | ||
) -> Result<FixedDecimalFormatter, DecimalError> { | ||
FixedDecimalFormatter::try_new_with_buffer_provider(self.0, locale, options) | ||
} | ||
} | ||
|
||
#[cfg(feature = "serde")] | ||
impl<P> WeekCalculatorLoader for ExternalLoaderBuffer<'_, P> | ||
where | ||
P: ?Sized + BufferProvider, | ||
{ | ||
#[inline] | ||
fn load(&self, locale: &DataLocale) -> Result<WeekCalculator, CalendarError> { | ||
WeekCalculator::try_new_with_buffer_provider(self.0, locale) | ||
} | ||
} | ||
|
||
/// Loader for types from other crates using [`DataProvider`]. | ||
pub(crate) struct ExternalLoaderUnstable<'a, P: ?Sized>(pub &'a P); | ||
|
||
impl<P> FixedDecimalFormatterLoader for ExternalLoaderUnstable<'_, P> | ||
where | ||
P: ?Sized + DataProvider<DecimalSymbolsV1Marker>, | ||
{ | ||
#[inline] | ||
fn load( | ||
&self, | ||
locale: &DataLocale, | ||
options: FixedDecimalFormatterOptions, | ||
) -> Result<FixedDecimalFormatter, DecimalError> { | ||
FixedDecimalFormatter::try_new_unstable(self.0, locale, options) | ||
} | ||
} | ||
|
||
impl<P> WeekCalculatorLoader for ExternalLoaderUnstable<'_, P> | ||
where | ||
P: ?Sized + DataProvider<WeekDataV2Marker>, | ||
{ | ||
#[inline] | ||
fn load(&self, locale: &DataLocale) -> Result<WeekCalculator, CalendarError> { | ||
WeekCalculator::try_new_unstable(self.0, locale) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
observation: must stay private, we may need to be able to load RBNF in the long run
in the medium term we will probably hardcode a
FixedDecimalFormatter | CustomFormat
where the CustomFormat is a simple enum with code attached.