Skip to content

Commit

Permalink
Add initial neo datetime FFI (#6035)
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored Feb 7, 2025
1 parent a503f5e commit ea6b265
Show file tree
Hide file tree
Showing 71 changed files with 4,545 additions and 1,085 deletions.
4 changes: 0 additions & 4 deletions components/datetime/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,6 @@ pub struct FieldSetBuilder {
pub year_style: Option<YearStyle>,
}

// This is the default length when the builder is used. This could have been defined in the macro
// that generates the `take_from_builder` fns, but it would be easily lost.
pub(crate) const DEFAULT_LENGTH: Length = Length::Medium;

enum DateOrCalendarPeriodFieldSet {
Date(DateFieldSet),
CalendarPeriod(CalendarPeriodFieldSet),
Expand Down
3 changes: 1 addition & 2 deletions components/datetime/src/fieldsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,12 @@ macro_rules! impl_marker_with_options {
}
}
/// Builds this field set, removing the needed options from the builder.
/// If length is needed but is None, falls back to `builder::DEFAULT_LENGTH`.
#[allow(unused)]
pub(crate) fn take_from_builder(
options: &mut builder::FieldSetBuilder
) -> Self {
Self {
$(length: yes_to!(options.length.take().unwrap_or(builder::DEFAULT_LENGTH), $sample_length),)?
$(length: yes_to!(options.length.take().unwrap_or_default(), $sample_length),)?
$(alignment: yes_to!(options.alignment.take(), $alignment_yes),)?
$(year_style: yes_to!(options.year_style.take(), $yearstyle_yes),)?
$(time_precision: yes_to!(options.time_precision.take(), $timeprecision_yes),)?
Expand Down
11 changes: 8 additions & 3 deletions components/datetime/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use crate::neo_serde::TimePrecisionSerde;
/// "January 1, 2000"
/// );
/// ```
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)]
#[cfg_attr(
all(feature = "serde", feature = "experimental"),
derive(serde::Serialize, serde::Deserialize)
Expand All @@ -73,6 +73,9 @@ pub enum Length {
/// A long date; typically spelled-out, as in “January 1, 2000”.
Long = 4,
/// A medium-sized date; typically abbreviated, as in “Jan. 1, 2000”.
///
/// This is the default.
#[default]
Medium = 3,
/// A short date; typically numeric, as in “1/1/2000”.
Short = 1,
Expand Down Expand Up @@ -128,7 +131,7 @@ impl IntoOption<Length> for Length {
/// "01/01/25"
/// );
/// ```
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)]
#[cfg_attr(
all(feature = "serde", feature = "experimental"),
derive(serde::Serialize, serde::Deserialize)
Expand All @@ -142,6 +145,7 @@ pub enum Alignment {
/// Align fields as the locale specifies them to be aligned.
///
/// This is the default option.
#[default]
Auto,
/// Align fields as appropriate for a column layout. For example:
///
Expand Down Expand Up @@ -257,7 +261,7 @@ impl IntoOption<Alignment> for Alignment {
/// "1/1/2025 AD"
/// );
/// ```
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)]
#[cfg_attr(
all(feature = "serde", feature = "experimental"),
derive(serde::Serialize, serde::Deserialize)
Expand All @@ -279,6 +283,7 @@ pub enum YearStyle {
/// - `77 AD`
/// - `1900`
/// - `'24`
#[default]
Auto,
/// Always display the century, and display the era when needed to
/// disambiguate the year, based on locale preferences.
Expand Down
5 changes: 3 additions & 2 deletions components/datetime/src/raw/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl DatePatternSelectionData {
pub(crate) fn select(&self, input: &ExtractedInput) -> DatePatternDataBorrowed {
match self {
DatePatternSelectionData::SkeletonDate { options, payload } => {
let year_style = options.year_style.unwrap_or(YearStyle::Auto);
let year_style = options.year_style.unwrap_or_default();
let variant = match (
year_style,
input
Expand Down Expand Up @@ -870,7 +870,8 @@ impl<'a> ItemsAndOptions<'a> {
#[allow(clippy::single_match)] // need `ref mut`, which doesn't work in `if let`?
match &mut pattern_item {
PatternItem::Field(ref mut field) => {
if matches!(self.alignment, Some(Alignment::Column))
let alignment = self.alignment.unwrap_or_default();
if matches!(alignment, Alignment::Column)
&& field.length == FieldLength::One
&& matches!(
field.symbol,
Expand Down
23 changes: 23 additions & 0 deletions ffi/capi/bindings/c/DateTimeAlignment.d.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions ffi/capi/bindings/c/DateTimeAlignment.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 46 additions & 11 deletions ffi/capi/bindings/c/DateTimeFormatter.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions ffi/capi/bindings/c/DateTimeFormatterGregorian.d.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ea6b265

Please sign in to comment.