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

Support fullYear in Serde #5371

Merged
merged 1 commit into from
Aug 15, 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
32 changes: 20 additions & 12 deletions components/datetime/src/neo_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ impl TryFrom<SemanticSkeletonSerde> 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,
Expand All @@ -83,6 +84,7 @@ enum FieldSetField {

impl FieldSetField {
const VALUES: &'static [FieldSetField] = &[
FullYear,
Year,
Month,
Day,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -255,12 +261,11 @@ impl From<NeoDayComponents> 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,
Expand All @@ -276,9 +281,11 @@ impl TryFrom<FieldSetSerde> 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),
}
Expand All @@ -291,10 +298,9 @@ impl From<NeoDateComponents> 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,
}
}
Expand All @@ -309,7 +315,9 @@ impl TryFrom<FieldSetSerde> 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),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"year": "numeric"
},
"semantic": {
"fieldSet": ["year"],
"fieldSet": ["fullYear"],
"length": "short"
}
}
Expand All @@ -29,7 +29,7 @@
"month": "numeric"
},
"semantic": {
"fieldSet": ["year", "month"],
"fieldSet": ["fullYear", "month"],
"length": "short"
}
}
Expand All @@ -51,7 +51,7 @@
"day": "numeric-day-of-month"
},
"semantic": {
"fieldSet": ["year", "month", "day"],
"fieldSet": ["fullYear", "month", "day"],
"length": "short"
}
}
Expand All @@ -74,7 +74,7 @@
"weekday": "short"
},
"semantic": {
"fieldSet": ["year", "month", "day", "weekday"],
"fieldSet": ["fullYear", "month", "day", "weekday"],
"length": "short"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"era": "short"
},
"semantic": {
"fieldSet": ["year"],
"fieldSet": ["fullYear"],
"length": "medium",
"eraDisplay": "always"
}
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/tests/fixtures/tests/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down