Skip to content

Commit

Permalink
Add EraDisplay to neo serde (#5314)
Browse files Browse the repository at this point in the history
Fixes main CI
  • Loading branch information
sffc authored Jul 26, 2024
1 parent 812028c commit 724131e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions components/datetime/src/neo_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! Serde definitions for semantic skeleta

use crate::neo_skeleton::{
NeoComponents, NeoDateComponents, NeoDayComponents, NeoSkeleton, NeoSkeletonLength,
EraDisplay, NeoComponents, NeoDateComponents, NeoDayComponents, NeoSkeleton, NeoSkeletonLength,
NeoTimeComponents, NeoTimeZoneSkeleton, NeoTimeZoneStyle,
};
use alloc::vec::Vec;
Expand All @@ -27,13 +27,16 @@ pub(crate) struct SemanticSkeletonSerde {
#[serde(rename = "fieldSet")]
pub(crate) field_set: NeoComponents,
pub(crate) length: NeoSkeletonLength,
#[serde(rename = "eraDisplay")]
pub(crate) era_display: Option<EraDisplay>,
}

impl From<NeoSkeleton> for SemanticSkeletonSerde {
fn from(value: NeoSkeleton) -> Self {
Self {
field_set: value.components,
length: value.length,
era_display: value.era_display,
}
}
}
Expand All @@ -44,6 +47,7 @@ impl TryFrom<SemanticSkeletonSerde> for NeoSkeleton {
Ok(NeoSkeleton {
length: value.length,
components: value.field_set,
era_display: value.era_display,
})
}
}
Expand Down Expand Up @@ -468,12 +472,13 @@ fn test_basic() {
NeoTimeZoneSkeleton::generic(),
),
length: NeoSkeletonLength::Medium,
era_display: Some(EraDisplay::Always),
};

let json_string = serde_json::to_string(&skeleton).unwrap();
assert_eq!(
json_string,
r#"{"fieldSet":["year","month","day","weekday","hour","minute","zoneGeneric"],"length":"medium"}"#
r#"{"fieldSet":["year","month","day","weekday","hour","minute","zoneGeneric"],"length":"medium","eraDisplay":"always"}"#
);
let json_skeleton = serde_json::from_str::<NeoSkeleton>(&json_string).unwrap();
assert_eq!(skeleton, json_skeleton);
Expand Down

0 comments on commit 724131e

Please sign in to comment.