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

split neo datetime patterns keys #4202

Merged
merged 6 commits into from
Oct 21, 2023
Merged
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
60 changes: 43 additions & 17 deletions components/datetime/src/provider/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@

mod adapter;

use crate::pattern::{self, runtime};
use crate::pattern::runtime;
use icu_provider::prelude::*;
use tinystr::UnvalidatedTinyAsciiStr;
use zerovec::ule::UnvalidatedStr;
use zerovec::{VarZeroVec, ZeroMap};

/// Symbols used for representing the year name
///
/// This uses an auxiliary key for length.
/// This uses an auxiliary subtag for length. The subtag is simply the number of
/// characters in the equivalent CLDR field syntax name, plus "s" for standalone contexts. For example,
/// "abbreviated" (e.g. `MMM`) is `-x-3` or `-x-3s` depending on whether it is format or standalone
/// respectively.
///
/// The full list is:
/// - 3 is "abbreviated"
/// - 4 is "narrow"
/// - 5 is "wide"
/// - 6 is "short" (weekdays only)
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
Expand Down Expand Up @@ -55,7 +64,7 @@ pub enum YearSymbolsV1<'data> {

/// Symbols used for representing the month name
///
/// This uses an auxiliary key for length.
/// This uses an auxiliary subtag for length. See [`YearSymbolsV1`] for more information on the scheme.
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
Expand Down Expand Up @@ -109,7 +118,7 @@ pub enum MonthSymbolsV1<'data> {
/// In the case noon is missing but midnight is present, the noon value can be the empty string. This is unlikely.
/// - For day names element 0 is the first day of the month
///
/// This uses an auxiliary key for length.
/// This uses an auxiliary subtag for length. See [`YearSymbolsV1`] for more information on the scheme.
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
Expand Down Expand Up @@ -139,19 +148,28 @@ pub struct LinearSymbolsV1<'data> {
pub symbols: VarZeroVec<'data, str>,
}

/// The default per-length patterns associated with dates and times
/// The default per-length patterns associated with dates
///
/// This uses an auxiliary key for length. time@1 additionally uses
/// the auxiliary key for representing hour cycle preferences.
/// This uses an auxiliary subtag for length. The subtag can be "f", "l", "m", "s" for
/// "full", "long", "medium", or "short".
///
/// <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>
#[icu_provider::data_struct(
marker(DatePatternV1Marker, "datetime/patterns/date@1"),
marker(TimePatternV1Marker, "datetime/patterns/time@1")
// date patterns
marker(BuddhistDatePatternV1Marker, "datetime/patterns/buddhist/date@1"),
marker(ChineseDatePatternV1Marker, "datetime/patterns/chinese/date@1"),
marker(CopticDatePatternV1Marker, "datetime/patterns/coptic/date@1"),
marker(DangiDatePatternV1Marker, "datetime/patterns/dangi/date@1"),
marker(EthiopianDatePatternV1Marker, "datetime/patterns/ethiopic/date@1"),
marker(GregorianDatePatternV1Marker, "datetime/patterns/gregory/date@1"),
marker(HebrewDatePatternV1Marker, "datetime/patterns/hebrew/date@1"),
marker(IndianDatePatternV1Marker, "datetime/patterns/indian/date@1"),
marker(IslamicDatePatternV1Marker, "datetime/patterns/islamic/date@1"),
marker(JapaneseDatePatternV1Marker, "datetime/patterns/japanese/date@1")
)]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(
Expand All @@ -161,36 +179,44 @@ pub struct LinearSymbolsV1<'data> {
)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[yoke(prove_covariance_manually)]
pub struct PatternV1<'data> {
pub struct DatePatternV1<'data> {
/// The pattern
#[cfg_attr(feature = "serde", serde(borrow))]
pub pattern: runtime::Pattern<'data>,
}

/// The default hour cycle intended to be used with a locale
/// The default per-length patterns associated with times
///
/// This uses an auxiliary subtag for length. See [`DatePatternV1`] for more information on the scheme.
///
/// It also uses the subtag to track hour cycles; the data for the default hour cycle will
/// use a regular length auxiliary subtag (e.g. `-x-f` for full), and the non-default
/// one will tack on a `h` or `k` depending on whether it is H11H12 or H23H24
/// (`-x-fk` for full, non-default, 23/24 hours)
///
/// <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>
#[icu_provider::data_struct(marker(PreferredHourCycleV1Marker, "datetime/patterns/hourcycle@1"))]
#[derive(Debug, PartialEq, Clone, Copy)]
#[icu_provider::data_struct(marker(TimePatternV1Marker, "datetime/patterns/time@1"))]
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(
feature = "datagen",
derive(serde::Serialize, databake::Bake),
databake(path = icu_datetime::provider::neo),
)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[yoke(prove_covariance_manually)]
pub struct PreferredHourCycleV1 {
/// The hour cycle preference
pub cycle: pattern::CoarseHourCycle,
pub struct TimePatternV1<'data> {
/// The pattern
#[cfg_attr(feature = "serde", serde(borrow))]
pub pattern: runtime::Pattern<'data>,
}

/// The default per-length patterns used for combining dates and times into datetimes
///
/// This uses an auxiliary key for length.
/// This uses an auxiliary subtag for length. See [`DatePatternV1`] for more information on the scheme.
///
/// <div class="stab unstable">
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
Expand Down