Skip to content

Commit

Permalink
DateTimeFormatter numbering_system getter draft
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Dec 17, 2024
1 parent 756afb6 commit 999f63b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions components/datetime/src/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use core::marker::PhantomData;
use icu_calendar::any_calendar::IntoAnyCalendar;
use icu_calendar::{AnyCalendar, AnyCalendarKind, AnyCalendarPreferences};
use icu_decimal::FixedDecimalFormatterPreferences;
use icu_locale_core::extensions::unicode::Value;
use icu_locale_core::preferences::extensions::unicode::keywords::{
CalendarAlgorithm, HourCycle, NumberingSystem,
};
Expand Down Expand Up @@ -795,6 +796,40 @@ impl<FSet: DateTimeMarkers> DateTimeFormatter<FSet> {
pub fn calendar_kind(&self) -> AnyCalendarKind {
self.calendar.kind()
}

/// Returns the numbering system used in this formatter.
///
/// If the fields do not require a number formatter, this could return `None`.
///
/// # Examples
///
/// ```
/// use icu::calendar::AnyCalendarKind;
/// use icu::calendar::Date;
/// use icu::datetime::fieldsets::YMD;
/// use icu::datetime::DateTimeFormatter;
/// use icu::locale::locale;
/// use writeable::assert_writeable_eq;
///
/// let formatter = DateTimeFormatter::try_new(
/// locale!("th").into(),
/// YMD::long(),
/// )
/// .unwrap();
///
/// assert_writeable_eq!(
/// formatter.format_any_calendar(&Date::try_new_iso(2024, 12, 16).unwrap()),
/// "16 ธันวาคม 2567"
/// );
///
/// assert_eq!(formatter.numbering_system().unwrap(), "latn");
/// ```
pub fn numbering_system(&self) -> Option<Value> {
self.names
.fixed_decimal_formatter
.as_ref()
.map(|f| f.numbering_system())
}
}

/// A formatter optimized for time and time zone formatting.
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/pattern/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub(crate) struct RawDateTimeNames<FSet: DateTimeNamesMarker> {
mz_periods:
<FSet::MetazoneLookup as DateTimeNamesHolderTrait<tz::MzPeriodV1Marker>>::Container<()>,
// TODO(#4340): Make the FixedDecimalFormatter optional
fixed_decimal_formatter: Option<FixedDecimalFormatter>,
pub(crate) fixed_decimal_formatter: Option<FixedDecimalFormatter>,
_marker: PhantomData<FSet>,
}

Expand Down

0 comments on commit 999f63b

Please sign in to comment.