Skip to content

Commit

Permalink
TimeZoneInfo (#5691)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored Oct 16, 2024
1 parent 297e06b commit f99af85
Show file tree
Hide file tree
Showing 87 changed files with 1,348 additions and 2,474 deletions.
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

0 comments on commit f99af85

Please sign in to comment.