From b8da6e83d5d8369bdce9e2ac559cea3906d1ff6f Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Wed, 14 Aug 2024 18:40:33 -0700 Subject: [PATCH] Support fullYear in Serde --- components/datetime/src/neo_serde.rs | 32 ++++++++++++------- .../tests/components-exact-matches.json | 8 ++--- .../tests/components-width-differences.json | 2 +- .../tests/fixtures/tests/components.json | 2 +- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/components/datetime/src/neo_serde.rs b/components/datetime/src/neo_serde.rs index d9008ced823..dd5e17f89e1 100644 --- a/components/datetime/src/neo_serde.rs +++ b/components/datetime/src/neo_serde.rs @@ -60,12 +60,13 @@ impl TryFrom for NeoSkeleton { #[serde(rename_all = "camelCase")] enum FieldSetField { // Day and Date Fields - Year = 0, - Month = 1, - Day = 2, - Weekday = 3, - WeekOfYear = 4, - WeekOfMonth = 5, + FullYear = 0, + Year = 1, + Month = 2, + Day = 3, + Weekday = 4, + WeekOfYear = 5, + WeekOfMonth = 6, // Time Fields Hour = 16, Minute = 17, @@ -83,6 +84,7 @@ enum FieldSetField { impl FieldSetField { const VALUES: &'static [FieldSetField] = &[ + FullYear, Year, Month, Day, @@ -146,15 +148,19 @@ impl FieldSetSerde { const DAY: Self = Self::from_fields(&[Day]); const MONTH_DAY: Self = Self::from_fields(&[Month, Day]); const YEAR_MONTH_DAY: Self = Self::from_fields(&[Year, Month, Day]); + const FULLYEAR_MONTH_DAY: Self = Self::from_fields(&[FullYear, Month, Day]); const DAY_WEEKDAY: Self = Self::from_fields(&[Day, Weekday]); const MONTH_DAY_WEEKDAY: Self = Self::from_fields(&[Month, Day, Weekday]); const YEAR_MONTH_DAY_WEEKDAY: Self = Self::from_fields(&[Year, Month, Day, Weekday]); + const FULLYEAR_MONTH_DAY_WEEKDAY: Self = Self::from_fields(&[FullYear, Month, Day, Weekday]); const WEEKDAY: Self = Self::from_fields(&[Weekday]); // Date Components const MONTH: Self = Self::from_fields(&[Month]); const YEAR_MONTH: Self = Self::from_fields(&[Year, Month]); + const FULLYEAR_MONTH: Self = Self::from_fields(&[FullYear, Month]); const YEAR: Self = Self::from_fields(&[Year]); + const FULLYEAR: Self = Self::from_fields(&[FullYear]); const YEAR_WEEK: Self = Self::from_fields(&[Year, WeekOfYear]); // Time Components @@ -255,12 +261,11 @@ impl From for FieldSetSerde { NeoDayComponents::Day => Self::DAY, NeoDayComponents::MonthDay => Self::MONTH_DAY, NeoDayComponents::YearMonthDay => Self::YEAR_MONTH_DAY, - // TODO: support eraDisplay - NeoDayComponents::EraYearMonthDay => Self::YEAR_MONTH_DAY, + NeoDayComponents::EraYearMonthDay => Self::FULLYEAR_MONTH_DAY, NeoDayComponents::DayWeekday => Self::DAY_WEEKDAY, NeoDayComponents::MonthDayWeekday => Self::MONTH_DAY_WEEKDAY, NeoDayComponents::YearMonthDayWeekday => Self::YEAR_MONTH_DAY_WEEKDAY, - NeoDayComponents::EraYearMonthDayWeekday => Self::YEAR_MONTH_DAY_WEEKDAY, + NeoDayComponents::EraYearMonthDayWeekday => Self::FULLYEAR_MONTH_DAY_WEEKDAY, NeoDayComponents::Weekday => Self::WEEKDAY, // TODO: support auto? NeoDayComponents::Auto => Self::YEAR_MONTH_DAY, @@ -276,9 +281,11 @@ impl TryFrom for NeoDayComponents { FieldSetSerde::DAY => Ok(Self::Day), FieldSetSerde::MONTH_DAY => Ok(Self::MonthDay), FieldSetSerde::YEAR_MONTH_DAY => Ok(Self::YearMonthDay), + FieldSetSerde::FULLYEAR_MONTH_DAY => Ok(Self::EraYearMonthDay), FieldSetSerde::DAY_WEEKDAY => Ok(Self::DayWeekday), FieldSetSerde::MONTH_DAY_WEEKDAY => Ok(Self::MonthDayWeekday), FieldSetSerde::YEAR_MONTH_DAY_WEEKDAY => Ok(Self::YearMonthDayWeekday), + FieldSetSerde::FULLYEAR_MONTH_DAY_WEEKDAY => Ok(Self::EraYearMonthDayWeekday), FieldSetSerde::WEEKDAY => Ok(Self::Weekday), _ => Err(Error::InvalidFields), } @@ -291,10 +298,9 @@ impl From for FieldSetSerde { NeoDateComponents::Day(day) => FieldSetSerde::from(day), NeoDateComponents::Month => Self::MONTH, NeoDateComponents::YearMonth => Self::YEAR_MONTH, - // TODO: support eraDisplay - NeoDateComponents::EraYearMonth => Self::YEAR_MONTH, + NeoDateComponents::EraYearMonth => Self::FULLYEAR_MONTH, NeoDateComponents::Year => Self::YEAR, - NeoDateComponents::EraYear => Self::YEAR, + NeoDateComponents::EraYear => Self::FULLYEAR, NeoDateComponents::YearWeek => Self::YEAR_WEEK, } } @@ -309,7 +315,9 @@ impl TryFrom for NeoDateComponents { match value { FieldSetSerde::MONTH => Ok(Self::Month), FieldSetSerde::YEAR_MONTH => Ok(Self::YearMonth), + FieldSetSerde::FULLYEAR_MONTH => Ok(Self::EraYearMonth), FieldSetSerde::YEAR => Ok(Self::Year), + FieldSetSerde::FULLYEAR => Ok(Self::EraYear), FieldSetSerde::YEAR_WEEK => Ok(Self::YearWeek), _ => Err(Error::InvalidFields), } diff --git a/components/datetime/tests/fixtures/tests/components-exact-matches.json b/components/datetime/tests/fixtures/tests/components-exact-matches.json index 7efc4e9598e..1e19cc8d6e4 100644 --- a/components/datetime/tests/fixtures/tests/components-exact-matches.json +++ b/components/datetime/tests/fixtures/tests/components-exact-matches.json @@ -8,7 +8,7 @@ "year": "numeric" }, "semantic": { - "fieldSet": ["year"], + "fieldSet": ["fullYear"], "length": "short" } } @@ -29,7 +29,7 @@ "month": "numeric" }, "semantic": { - "fieldSet": ["year", "month"], + "fieldSet": ["fullYear", "month"], "length": "short" } } @@ -51,7 +51,7 @@ "day": "numeric-day-of-month" }, "semantic": { - "fieldSet": ["year", "month", "day"], + "fieldSet": ["fullYear", "month", "day"], "length": "short" } } @@ -74,7 +74,7 @@ "weekday": "short" }, "semantic": { - "fieldSet": ["year", "month", "day", "weekday"], + "fieldSet": ["fullYear", "month", "day", "weekday"], "length": "short" } } diff --git a/components/datetime/tests/fixtures/tests/components-width-differences.json b/components/datetime/tests/fixtures/tests/components-width-differences.json index 7214600fc9d..8564d69dd8e 100644 --- a/components/datetime/tests/fixtures/tests/components-width-differences.json +++ b/components/datetime/tests/fixtures/tests/components-width-differences.json @@ -29,7 +29,7 @@ "era": "short" }, "semantic": { - "fieldSet": ["year"], + "fieldSet": ["fullYear"], "length": "medium", "eraDisplay": "always" } diff --git a/components/datetime/tests/fixtures/tests/components.json b/components/datetime/tests/fixtures/tests/components.json index 7a5e1865814..41a15a0f488 100644 --- a/components/datetime/tests/fixtures/tests/components.json +++ b/components/datetime/tests/fixtures/tests/components.json @@ -14,7 +14,7 @@ "second": "numeric" }, "semantic": { - "fieldSet": ["year", "month", "day", "weekday", "hour", "minute", "second"], + "fieldSet": ["fullYear", "month", "day", "weekday", "hour", "minute", "second"], "length": "long", "eraDisplay": "always" }