Skip to content

Commit 6708604

Browse files
committed
use RDs
1 parent 01c0637 commit 6708604

5 files changed

Lines changed: 22 additions & 13 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ timezone_provider = { workspace = true }
9393
# System time feature
9494
web-time = { workspace = true, optional = true }
9595
iana-time-zone = { workspace = true, optional = true }
96+
calendrical_calculations = "0.2.4"
9697

9798
[dev-dependencies]
9899
timezone_provider = { workspace = true, features = ["zoneinfo64", "experimental_tzif"] }

src/builtins/core/calendar.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ use icu_calendar::{
2424
};
2525
use icu_calendar::{
2626
cal::{HijriTabularEpoch, HijriTabularLeapYears},
27+
options::DateDurationUnit as IcuUnit,
2728
options::{
2829
DateAddOptions, DateDifferenceOptions, DateFromFieldsOptions, MissingFieldsStrategy,
2930
Overflow as IcuOverflow,
3031
},
3132
preferences::CalendarAlgorithm,
3233
types::DateDuration as IcuDateDuration,
33-
options::DateDurationUnit as IcuUnit,
3434
types::DateFields,
3535
Gregorian,
3636
};
@@ -152,8 +152,13 @@ impl Calendar {
152152
const { &AnyCalendar::HijriUmmAlQura(Hijri::new_umm_al_qura()) }
153153
}
154154
AnyCalendarKind::Iso => &AnyCalendar::Iso(Iso),
155-
#[allow(deprecated, reason = "need to match on JapaneseExtended for exhaustiveness")]
156-
AnyCalendarKind::Japanese | AnyCalendarKind::JapaneseExtended => const { &AnyCalendar::Japanese(Japanese::new()) },
155+
#[allow(
156+
deprecated,
157+
reason = "need to match on JapaneseExtended for exhaustiveness"
158+
)]
159+
AnyCalendarKind::Japanese | AnyCalendarKind::JapaneseExtended => {
160+
const { &AnyCalendar::Japanese(Japanese::new()) }
161+
}
157162
AnyCalendarKind::Persian => &AnyCalendar::Persian(Persian),
158163
AnyCalendarKind::Roc => &AnyCalendar::Roc(Roc),
159164
_ => {

src/error.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::fmt;
44
use ixdtf::ParseError;
55
use timezone_provider::TimeZoneProviderError;
66

7-
use icu_calendar::error::{DateFromFieldsError, DateAddError};
7+
use icu_calendar::error::{DateAddError, DateFromFieldsError};
88

99
/// `TemporalError`'s error type.
1010
#[derive(Debug, Default, Clone, Copy, PartialEq)]
@@ -166,7 +166,6 @@ impl From<DateAddError> for TemporalError {
166166
}
167167
}
168168

169-
170169
impl From<ParseError> for TemporalError {
171170
fn from(error: ParseError) -> Self {
172171
TemporalError::range().with_enum(ErrorMessage::Ixdtf(error))
@@ -271,17 +270,19 @@ impl ErrorMessage {
271270
Self::Ixdtf(s) => ixdtf_error_to_static_string(s),
272271

273272
Self::Icu4xDateFromFields(DateFromFieldsError::InvalidEra) => "Unknown era.",
274-
Self::Icu4xDateFromFields(DateFromFieldsError::InvalidDay {..}) | Self::Icu4xDateAdd(DateAddError::InvalidDay {..}) => "Day out of range",
275-
Self::Icu4xDateFromFields(DateFromFieldsError::InvalidOrdinalMonth {..}) => "Month out of range",
273+
Self::Icu4xDateFromFields(DateFromFieldsError::InvalidDay { .. })
274+
| Self::Icu4xDateAdd(DateAddError::InvalidDay { .. }) => "Day out of range",
275+
Self::Icu4xDateFromFields(DateFromFieldsError::InvalidOrdinalMonth { .. }) => {
276+
"Month out of range"
277+
}
276278
Self::Icu4xDateFromFields(DateFromFieldsError::MonthCodeInvalidSyntax) => {
277279
"Invalid month code."
278280
}
279281
Self::Icu4xDateFromFields(DateFromFieldsError::MonthNotInCalendar) => {
280282
"Month code not in calendar."
281283
}
282-
Self::Icu4xDateFromFields(DateFromFieldsError::MonthNotInYear) | Self::Icu4xDateAdd(DateAddError::MonthNotInYear) => {
283-
"Month code not in year."
284-
}
284+
Self::Icu4xDateFromFields(DateFromFieldsError::MonthNotInYear)
285+
| Self::Icu4xDateAdd(DateAddError::MonthNotInYear) => "Month code not in year.",
285286
Self::Icu4xDateFromFields(DateFromFieldsError::InconsistentYear) => {
286287
"Inconsistent year."
287288
}

src/iso.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,10 @@ impl IsoDate {
507507
impl IsoDate {
508508
/// Creates `[[ISOYear]]`, `[[isoMonth]]`, `[[isoDay]]` fields from `ICU4X`'s `Date<Iso>` struct.
509509
pub(crate) fn to_icu4x(self) -> IcuDate<Iso> {
510-
let d = IcuDate::try_new_iso(self.year, self.month, self.day);
511-
debug_assert!(d.is_ok(), "ICU4X ISODate conversion must not fail");
512-
d.unwrap_or_else(|_| IcuDate::from_rata_die(icu_calendar::types::RataDie::new(0), Iso))
510+
let rd = calendrical_calculations::gregorian::fixed_from_gregorian(
511+
self.year, self.month, self.day,
512+
);
513+
IcuDate::from_rata_die(rd, Iso)
513514
}
514515

515516
pub(crate) fn from_icu4x(date: <Iso as IcuCalendar>::DateInner) -> Self {

0 commit comments

Comments
 (0)