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

TimeZoneInfo #5691

Merged
merged 22 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
4 changes: 2 additions & 2 deletions components/datetime/README.md

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

4 changes: 2 additions & 2 deletions components/datetime/benches/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use icu_datetime::neo::TypedNeoFormatter;

use icu_calendar::{DateTime, Gregorian};
use icu_locale_core::Locale;
use icu_timezone::{CustomTimeZone, CustomZonedDateTime};
use icu_timezone::{CustomZonedDateTime, TimeZoneInfo};
use writeable::TryWriteable;

#[path = "../tests/mock.rs"]
Expand All @@ -35,7 +35,7 @@ fn datetime_benches(c: &mut Criterion) {
date,
time,
// zone is unused but we need to make the types match
zone: CustomTimeZone::utc(),
zone: TimeZoneInfo::utc(),
}
}
})
Expand Down
69 changes: 41 additions & 28 deletions components/datetime/src/format/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ use crate::fields::{self, Day, Field, FieldLength, FieldSymbol, Second, Week, Ye
use crate::input::ExtractedInput;
use crate::pattern::runtime::PatternMetadata;
use crate::pattern::PatternItem;
use crate::time_zone::{FormatTimeZone, FormatTimeZoneError, Iso8601Format};
use crate::time_zone::{IsoFormat, IsoMinutes, IsoSeconds, ResolvedNeoTimeZoneSkeleton};
use crate::time_zone::{
FormatTimeZone, FormatTimeZoneError, Iso8601Format, IsoFormat, IsoMinutes, IsoSeconds,
ResolvedNeoTimeZoneSkeleton,
};

use core::fmt::{self, Write};
use fixed_decimal::FixedDecimal;
Expand Down Expand Up @@ -471,49 +473,60 @@ where
}
Some(time_zone) => {
let payloads = datetime_names.get_payloads();
let mut r = Err(DateTimeWriteError::MissingNames(field));
let mut r = Err(FormatTimeZoneError::Fallback);
for formatter in time_zone.units() {
match formatter.format(w, input, payloads, fdf)? {
Ok(()) => {
r = Ok(());
break;
}
Err(FormatTimeZoneError::Fallback) => {
// Expected common case: the unit needs fall back to the next one
continue;
}
Err(FormatTimeZoneError::MissingInputField(f)) => {
r = Err(DateTimeWriteError::MissingInputField(f));
break;
}
Err(FormatTimeZoneError::MissingZoneSymbols) => {
r = Err(DateTimeWriteError::MissingNames(field));
break;
}
Err(FormatTimeZoneError::MissingFixedDecimalFormatter) => {
r = Err(DateTimeWriteError::MissingFixedDecimalFormatter);
r2 => {
r = r2;
break;
}
}
}

match r {
Ok(()) => Ok(()),
Err(DateTimeWriteError::MissingInputField(_)) => {
Err(FormatTimeZoneError::MissingInputField(f)) => {
write_value_missing(w, field)?;
r
Err(DateTimeWriteError::MissingInputField(f))
}
_ => {
w.with_part(Part::ERROR, |w| match input.offset {
Some(offset) => Iso8601Format {
format: IsoFormat::Basic,
minutes: IsoMinutes::Required,
seconds: IsoSeconds::Optional,
Err(
e @ (FormatTimeZoneError::MissingFixedDecimalFormatter
| FormatTimeZoneError::MissingZoneSymbols),
) => {
if let Some(offset) = input.offset {
w.with_part(Part::ERROR, |w| {
Iso8601Format {
format: IsoFormat::Basic,
minutes: IsoMinutes::Required,
seconds: IsoSeconds::Optional,
}
.format_infallible(w, offset)
})?;
} else {
write_value_missing(w, field)?;
}
Err(match e {
FormatTimeZoneError::MissingFixedDecimalFormatter => {
DateTimeWriteError::MissingFixedDecimalFormatter
}
FormatTimeZoneError::MissingZoneSymbols => {
DateTimeWriteError::MissingNames(field)
}
.format_infallible(w, offset),
None => "{GMT+?}".write_to(w),
_ => unreachable!(),
})
}
Err(FormatTimeZoneError::Fallback) => {
// unreachable because our current fallback chains don't fall through
w.with_part(Part::ERROR, |w| {
w.write_str("{unsupported:")?;
w.write_char(char::from(field.symbol))?;
w.write_str("}")
})?;
r
Err(DateTimeWriteError::UnsupportedField(field))
}
}
}
Expand Down
Loading
Loading