Skip to content
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
10 changes: 6 additions & 4 deletions components/datetime/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::error::DateTimeFormatError as Error;
use crate::fields::{self, FieldLength, FieldSymbol};
use crate::pattern::{Pattern, PatternItem};
use crate::provider;
use crate::provider::helpers::DateTimeDates;
use crate::provider::helpers::DateTimeSymbols;
use icu_locid::Locale;
use std::fmt;
use writeable::Writeable;
Expand Down Expand Up @@ -145,7 +145,7 @@ where
field.length,
)?,
length => {
let symbol = data.get_symbol_for_month(
let symbol = data.symbols.get_symbol_for_month(
month,
length,
date_time
Expand All @@ -163,7 +163,9 @@ where
.date_time()
.iso_weekday()
.ok_or(Error::MissingInputField)?;
let symbol = data.get_symbol_for_weekday(weekday, field.length, dow);
let symbol = data
.symbols
.get_symbol_for_weekday(weekday, field.length, dow);
w.write_str(symbol)?
}
FieldSymbol::Day(..) => format_number(
Expand Down Expand Up @@ -224,7 +226,7 @@ where
field.length,
)?,
FieldSymbol::DayPeriod(period) => {
let symbol = data.get_symbol_for_day_period(
let symbol = data.symbols.get_symbol_for_day_period(
period,
field.length,
date_time
Expand Down
7 changes: 5 additions & 2 deletions components/datetime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub mod options;
pub mod pattern;
pub mod provider;

use crate::provider::helpers::DateTimeDates;
use crate::provider::helpers::DateTimePatterns;
use date::DateTimeInput;
pub use error::DateTimeFormatError;
use format::write_pattern;
Expand Down Expand Up @@ -175,7 +175,10 @@ impl<'d> DateTimeFormat<'d> {
})?
.take_payload()?;

let pattern = data.get_pattern_for_options(options)?.unwrap_or_default();
let pattern = data
.patterns
.get_pattern_for_options(options)?
.unwrap_or_default();

Ok(Self {
locale,
Expand Down
25 changes: 15 additions & 10 deletions components/datetime/src/provider/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::borrow::Cow;

type Result<T> = std::result::Result<T, DateTimeFormatError>;

pub trait DateTimeDates {
pub trait DateTimePatterns {
fn get_pattern_for_options(&self, options: &DateTimeFormatOptions) -> Result<Option<Pattern>>;
fn get_pattern_for_style_bag(&self, style: &style::Bag) -> Result<Option<Pattern>>;
fn get_pattern_for_date_style(&self, style: style::Date) -> Result<Pattern>;
Expand All @@ -23,6 +23,9 @@ pub trait DateTimeDates {
date: Pattern,
time: Pattern,
) -> Result<Pattern>;
}

pub trait DateTimeSymbols {
fn get_symbol_for_month(
&self,
month: fields::Month,
Expand All @@ -44,7 +47,7 @@ pub trait DateTimeDates {
) -> &Cow<str>;
}

impl DateTimeDates for provider::gregory::DatesV1 {
impl DateTimePatterns for provider::gregory::PatternsV1 {
fn get_pattern_for_options(&self, options: &DateTimeFormatOptions) -> Result<Option<Pattern>> {
match options {
DateTimeFormatOptions::Style(bag) => self.get_pattern_for_style_bag(bag),
Expand All @@ -68,7 +71,7 @@ impl DateTimeDates for provider::gregory::DatesV1 {
}

fn get_pattern_for_date_style(&self, style: style::Date) -> Result<Pattern> {
let date = &self.patterns.date;
let date = &self.date;
let s = match style {
style::Date::Full => &date.full,
style::Date::Long => &date.long,
Expand All @@ -84,7 +87,7 @@ impl DateTimeDates for provider::gregory::DatesV1 {
date: Pattern,
time: Pattern,
) -> Result<Pattern> {
let date_time = &self.patterns.date_time;
let date_time = &self.date_time;
let s = match style {
style::Date::Full => &date_time.full,
style::Date::Long => &date_time.long,
Expand All @@ -95,7 +98,7 @@ impl DateTimeDates for provider::gregory::DatesV1 {
}

fn get_pattern_for_time_style(&self, style: style::Time) -> Result<Pattern> {
let time = &self.patterns.time;
let time = &self.time;
let s = match style {
style::Time::Full => &time.full,
style::Time::Long => &time.long,
Expand All @@ -104,17 +107,19 @@ impl DateTimeDates for provider::gregory::DatesV1 {
};
Ok(Pattern::from_bytes(s)?)
}
}

impl DateTimeSymbols for provider::gregory::DateSymbolsV1 {
fn get_symbol_for_weekday(
&self,
weekday: fields::Weekday,
length: fields::FieldLength,
day: date::IsoWeekday,
) -> &Cow<str> {
let widths = match weekday {
fields::Weekday::Format => &self.symbols.weekdays.format,
fields::Weekday::Format => &self.weekdays.format,
fields::Weekday::StandAlone => {
if let Some(ref widths) = self.symbols.weekdays.stand_alone {
if let Some(ref widths) = self.weekdays.stand_alone {
let symbols = match length {
fields::FieldLength::Wide => widths.wide.as_ref(),
fields::FieldLength::Narrow => widths.narrow.as_ref(),
Expand Down Expand Up @@ -153,9 +158,9 @@ impl DateTimeDates for provider::gregory::DatesV1 {
// TODO(#493): Support symbols for non-Gregorian calendars.
debug_assert!(num < 12);
let widths = match month {
fields::Month::Format => &self.symbols.months.format,
fields::Month::Format => &self.months.format,
fields::Month::StandAlone => {
if let Some(ref widths) = self.symbols.months.stand_alone {
if let Some(ref widths) = self.months.stand_alone {
let symbols = match length {
fields::FieldLength::Wide => widths.wide.as_ref(),
fields::FieldLength::Narrow => widths.narrow.as_ref(),
Expand Down Expand Up @@ -187,7 +192,7 @@ impl DateTimeDates for provider::gregory::DatesV1 {
is_top_of_hour: bool,
) -> &Cow<str> {
use fields::{DayPeriod::NoonMidnight, FieldLength};
let widths = &self.symbols.day_periods.format;
let widths = &self.day_periods.format;
let symbols = match length {
FieldLength::Wide => &widths.wide,
FieldLength::Narrow => &widths.narrow,
Expand Down