diff --git a/Cargo.lock b/Cargo.lock index 479a20aa8..5d9f9dd56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,7 +125,7 @@ dependencies = [ "serde_json", "syn", "timezone_provider", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", ] [[package]] @@ -168,7 +168,7 @@ dependencies = [ [[package]] name = "calendrical_calculations" version = "0.2.2" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "core_maths", "displaydoc", @@ -272,7 +272,7 @@ dependencies = [ [[package]] name = "databake" version = "0.2.0" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "databake-derive", "proc-macro2", @@ -282,7 +282,7 @@ dependencies = [ [[package]] name = "databake-derive" version = "0.2.0" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "proc-macro2", "quote", @@ -439,47 +439,47 @@ dependencies = [ [[package]] name = "icu_calendar" version = "2.0.4" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ - "calendrical_calculations 0.2.2 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "calendrical_calculations 0.2.2 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", "displaydoc", "icu_calendar_data", "icu_locale", - "icu_locale_core 2.0.0 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "icu_locale_core 2.0.0 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", "icu_provider", - "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", ] [[package]] name = "icu_calendar_data" version = "2.0.0" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" [[package]] name = "icu_collections" version = "2.0.0" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "displaydoc", - "potential_utf 0.1.3 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", - "yoke 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", - "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "potential_utf 0.1.3 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", + "yoke 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", + "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", ] [[package]] name = "icu_locale" version = "2.0.0" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "icu_collections", - "icu_locale_core 2.0.0 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "icu_locale_core 2.0.0 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", "icu_locale_data", "icu_provider", - "potential_utf 0.1.3 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", - "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "potential_utf 0.1.3 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", + "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", ] [[package]] @@ -497,35 +497,35 @@ dependencies = [ [[package]] name = "icu_locale_core" version = "2.0.0" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "displaydoc", - "litemap 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "litemap 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", "serde", - "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", - "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", + "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", ] [[package]] name = "icu_locale_data" version = "2.0.0" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" [[package]] name = "icu_provider" version = "2.0.0" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "displaydoc", - "icu_locale_core 2.0.0 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "icu_locale_core 2.0.0 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", "serde", "stable_deref_trait", - "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", - "yoke 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", - "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", + "yoke 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", + "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", "zerotrie", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", ] [[package]] @@ -568,7 +568,7 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "ixdtf" version = "0.6.3" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" [[package]] name = "jiff-tzdb" @@ -607,7 +607,7 @@ checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" [[package]] name = "litemap" version = "0.8.0" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "serde_core", ] @@ -660,11 +660,11 @@ checksum = "84df19adbe5b5a0782edcab45899906947ab039ccf4573713735ee7de1e6b08a" [[package]] name = "potential_utf" version = "0.1.3" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "serde_core", - "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", ] [[package]] @@ -870,7 +870,7 @@ dependencies = [ "num-traits", "temporal_rs", "timezone_provider", - "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", "zoneinfo64", ] @@ -887,9 +887,9 @@ dependencies = [ "num-traits", "resb", "timezone_provider", - "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", "web-time", - "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", "zoneinfo64", ] @@ -902,11 +902,11 @@ dependencies = [ "jiff-tzdb", "serde", "serde_json", - "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", "tzif", "yoke 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "zerotrie", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", "zoneinfo64", "zoneinfo_rs", ] @@ -924,12 +924,12 @@ dependencies = [ [[package]] name = "tinystr" version = "0.8.1" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "databake", "displaydoc", "serde_core", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", ] [[package]] @@ -1234,7 +1234,7 @@ checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" [[package]] name = "writeable" version = "0.6.1" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" [[package]] name = "yoke" @@ -1251,11 +1251,11 @@ dependencies = [ [[package]] name = "yoke" version = "0.8.0" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "stable_deref_trait", - "yoke-derive 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", - "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "yoke-derive 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", + "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", ] [[package]] @@ -1273,7 +1273,7 @@ dependencies = [ [[package]] name = "yoke-derive" version = "0.8.0" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "proc-macro2", "quote", @@ -1293,9 +1293,9 @@ dependencies = [ [[package]] name = "zerofrom" version = "0.1.6" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ - "zerofrom-derive 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "zerofrom-derive 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", ] [[package]] @@ -1313,7 +1313,7 @@ dependencies = [ [[package]] name = "zerofrom-derive" version = "0.1.6" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "proc-macro2", "quote", @@ -1324,13 +1324,13 @@ dependencies = [ [[package]] name = "zerotrie" version = "0.2.2" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "databake", "displaydoc", - "litemap 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "litemap 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", "serde_core", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", ] [[package]] @@ -1345,19 +1345,19 @@ dependencies = [ [[package]] name = "zerovec" version = "0.11.4" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "databake", "serde", - "yoke 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", - "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=5a56323558)", + "yoke 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", + "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=8262b4a)", "zerovec-derive", ] [[package]] name = "zerovec-derive" version = "0.11.1" -source = "git+https://github.com/unicode-org/icu4x?rev=5a56323558#5a56323558fb5732046be79ef2119278ce26758e" +source = "git+https://github.com/unicode-org/icu4x?rev=8262b4a#8262b4aafbafdbb0ebf05d21c3c680a94b852a5b" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index e3a342ee4..a41a30b60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,22 +34,22 @@ timezone_provider = { version = "~0.1.0", path = "./provider" } zoneinfo_rs = { version = "~0.0.17", path = "./zoneinfo" } # Dependencies -tinystr = { git = "https://github.com/unicode-org/icu4x", rev = "5a56323558" } -icu_calendar = { git = "https://github.com/unicode-org/icu4x", rev = "5a56323558", default-features = false } -icu_locale = { git = "https://github.com/unicode-org/icu4x", rev = "5a56323558" } +tinystr = { git = "https://github.com/unicode-org/icu4x", rev = "8262b4a" } +icu_calendar = { git = "https://github.com/unicode-org/icu4x", rev = "8262b4a", default-features = false } +icu_locale = { git = "https://github.com/unicode-org/icu4x", rev = "8262b4a" } rustc-hash = "2.1.0" num-traits = { version = "0.2.19", default-features = false } -ixdtf = { git = "https://github.com/unicode-org/icu4x", rev = "5a56323558" } +ixdtf = { git = "https://github.com/unicode-org/icu4x", rev = "8262b4a" } iana-time-zone = "0.1.64" log = "0.4.28" tzif = "0.4.0" jiff-tzdb = "0.1.4" combine = "4.6.7" web-time = "1.1.0" -zerovec = { git = "https://github.com/unicode-org/icu4x", rev = "5a56323558" } -databake = { git = "https://github.com/unicode-org/icu4x", rev = "5a56323558" } -zerotrie = { git = "https://github.com/unicode-org/icu4x", rev = "5a56323558" } -writeable = { git = "https://github.com/unicode-org/icu4x", rev = "5a56323558" } +zerovec = { git = "https://github.com/unicode-org/icu4x", rev = "8262b4a" } +databake = { git = "https://github.com/unicode-org/icu4x", rev = "8262b4a" } +zerotrie = { git = "https://github.com/unicode-org/icu4x", rev = "8262b4a" } +writeable = { git = "https://github.com/unicode-org/icu4x", rev = "8262b4a" } zoneinfo64 = "0.2.0" # Diplomat diff --git a/src/builtins/core/calendar.rs b/src/builtins/core/calendar.rs index 50296ed7c..ddb30c407 100644 --- a/src/builtins/core/calendar.rs +++ b/src/builtins/core/calendar.rs @@ -7,6 +7,7 @@ use crate::{ builtins::core::{ duration::DateDuration, Duration, PlainDate, PlainDateTime, PlainMonthDay, PlainYearMonth, }, + error::ErrorMessage, iso::IsoDate, options::{Overflow, Unit}, parsers::parse_allowed_calendar_formats, @@ -24,8 +25,13 @@ use icu_calendar::{ }; use icu_calendar::{ cal::{HijriTabularEpoch, HijriTabularLeapYears}, - options::{DateFromFieldsOptions, MissingFieldsStrategy, Overflow as IcuOverflow}, + options::{ + DateAddOptions, DateDifferenceOptions, DateFromFieldsOptions, MissingFieldsStrategy, + Overflow as IcuOverflow, + }, preferences::CalendarAlgorithm, + types::DateDuration as IcuDateDuration, + types::DateDurationUnit as IcuUnit, types::DateFields, types::MonthCode as IcuMonthCode, Gregorian, @@ -217,6 +223,22 @@ impl From for IcuOverflow { } } +impl TryFrom for IcuUnit { + type Error = TemporalError; + fn try_from(other: Unit) -> TemporalResult { + Ok(match other { + Unit::Day => IcuUnit::Days, + Unit::Week => IcuUnit::Weeks, + Unit::Month => IcuUnit::Months, + Unit::Year => IcuUnit::Years, + _ => { + return Err(TemporalError::r#type() + .with_message("Found time unit when computing CalendarDateUntil.")) + } + }) + } +} + impl<'a> TryFrom<&'a CalendarFields> for DateFields<'a> { type Error = TemporalError; fn try_from(other: &'a CalendarFields) -> TemporalResult { @@ -419,7 +441,32 @@ impl Calendar { return PlainDate::try_new(result.year, result.month, result.day, self.clone()); } - Err(TemporalError::range().with_message("Not yet implemented.")) + // This should be a valid duration at this point so we can just call .abs() + let invalid = TemporalError::range().with_enum(ErrorMessage::DurationNotValid); + let duration = IcuDateDuration { + is_negative: duration.years < 0 + || duration.months < 0 + || duration.weeks < 0 + || duration.days < 0, + years: u32::try_from(duration.years.abs()).map_err(|_| invalid)?, + months: u32::try_from(duration.months.abs()).map_err(|_| invalid)?, + weeks: u32::try_from(duration.weeks.abs()).map_err(|_| invalid)?, + days: u64::try_from(duration.days.abs()).map_err(|_| invalid)?, + }; + let mut options = DateAddOptions::default(); + options.overflow = Some(overflow.into()); + let calendar_date = self.0.from_iso(*date.to_icu4x().inner()); + + let added = self.0.add(&calendar_date, duration, options)?; + + let iso = self.0.to_iso(&added); + PlainDate::new_with_overflow( + Iso.extended_year(&iso), + Iso.month(&iso).ordinal, + Iso.day_of_month(&iso).0, + self.clone(), + overflow, + ) } /// `CalendarDateUntil` @@ -433,7 +480,24 @@ impl Calendar { let date_duration = one.diff_iso_date(two, largest_unit)?; return Ok(Duration::from(date_duration)); } - Err(TemporalError::range().with_message("Not yet implemented.")) + let mut options = DateDifferenceOptions::default(); + options.largest_unit = Some(largest_unit.try_into()?); + let calendar_date1 = self.0.from_iso(*one.to_icu4x().inner()); + let calendar_date2 = self.0.from_iso(*two.to_icu4x().inner()); + + let added = self.0.until(&calendar_date1, &calendar_date2, options)?; + + let days = added + .days + .try_into() + .map_err(|_| TemporalError::range().with_enum(ErrorMessage::DurationNotValid))?; + let duration = DateDuration::new( + added.years.into(), + added.months.into(), + added.weeks.into(), + days, + )?; + Ok(Duration::from(duration)) } /// `CalendarEra` diff --git a/src/builtins/core/duration.rs b/src/builtins/core/duration.rs index fc19e7912..efc63106c 100644 --- a/src/builtins/core/duration.rs +++ b/src/builtins/core/duration.rs @@ -636,7 +636,7 @@ impl Duration { microseconds, nanoseconds, ) { - return Err(TemporalError::range().with_message("Duration was not valid.")); + return Err(TemporalError::range().with_enum(ErrorMessage::DurationNotValid)); } let sign = duration_sign(&[ years, diff --git a/src/error.rs b/src/error.rs index 9ea0623ae..0e5847477 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,7 +4,7 @@ use core::fmt; use ixdtf::ParseError; use timezone_provider::TimeZoneProviderError; -use icu_calendar::DateError; +use icu_calendar::{cal::AnyCalendarDifferenceError, DateError}; /// `TemporalError`'s error type. #[derive(Debug, Default, Clone, Copy, PartialEq)] @@ -158,6 +158,12 @@ impl From for TemporalError { } } +impl From for TemporalError { + fn from(error: AnyCalendarDifferenceError) -> Self { + TemporalError::range().with_enum(ErrorMessage::Icu4xUntil(error)) + } +} + impl From for TemporalError { fn from(error: ParseError) -> Self { TemporalError::range().with_enum(ErrorMessage::Ixdtf(error)) @@ -173,6 +179,7 @@ pub(crate) enum ErrorMessage { ZDTOutOfDayBounds, LargestUnitCannotBeDateUnit, DateOutOfRange, + DurationNotValid, // Numerical errors NumberNotFinite, @@ -211,6 +218,7 @@ pub(crate) enum ErrorMessage { String(&'static str), Ixdtf(ParseError), Icu4xDate(DateError), + Icu4xUntil(AnyCalendarDifferenceError), } impl ErrorMessage { @@ -223,6 +231,7 @@ impl ErrorMessage { Self::ZDTOutOfDayBounds => "ZonedDateTime is outside the expected day bounds", Self::LargestUnitCannotBeDateUnit => "Largest unit cannot be a date unit", Self::DateOutOfRange => "Date is not within ISO date time limits.", + Self::DurationNotValid => "Duration was not valid.", Self::NumberNotFinite => "number value is not a finite value.", Self::NumberNotIntegral => "value must be integral.", Self::NumberNotPositive => "integer must be positive.", @@ -267,6 +276,10 @@ impl ErrorMessage { Self::Icu4xDate(DateError::InconsistentMonth) => "Inconsistent month/monthCode.", Self::Icu4xDate(DateError::NotEnoughFields) => "Insufficient fields.", Self::Icu4xDate(_) => "Date error.", + Self::Icu4xUntil(AnyCalendarDifferenceError::MismatchedCalendars) => { + "Mismatched calendars." + } + Self::Icu4xUntil(_) => "Arithmetic error.", } } }