From 293ab76b7fe89302c0214e60c7ee5470e8d5a71a Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 22 Oct 2025 10:26:45 -0700 Subject: [PATCH] Update ICU4X --- Cargo.lock | 120 +++++++++++++++++----------------- Cargo.toml | 16 ++--- src/builtins/core/calendar.rs | 30 ++------- src/error.rs | 54 +++++++++++---- 4 files changed, 116 insertions(+), 104 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e5988f08..3c221253d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "allocator-api2" @@ -125,7 +125,7 @@ dependencies = [ "serde_json", "syn", "timezone_provider", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", ] [[package]] @@ -168,7 +168,7 @@ dependencies = [ [[package]] name = "calendrical_calculations" version = "0.2.2" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" 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=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" 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=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" 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=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" dependencies = [ - "calendrical_calculations 0.2.2 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "calendrical_calculations 0.2.2 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", "displaydoc", "icu_calendar_data", "icu_locale", - "icu_locale_core 2.0.0 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "icu_locale_core 2.0.0 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", "icu_provider", - "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", ] [[package]] name = "icu_calendar_data" version = "2.0.0" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" [[package]] name = "icu_collections" version = "2.0.0" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" dependencies = [ "displaydoc", - "potential_utf 0.1.3 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", - "yoke 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", - "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "potential_utf 0.1.3 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", + "yoke 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", + "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", ] [[package]] name = "icu_locale" version = "2.0.0" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" dependencies = [ "icu_collections", - "icu_locale_core 2.0.0 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "icu_locale_core 2.0.0 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", "icu_locale_data", "icu_provider", - "potential_utf 0.1.3 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", - "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "potential_utf 0.1.3 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", + "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", ] [[package]] @@ -497,35 +497,35 @@ dependencies = [ [[package]] name = "icu_locale_core" version = "2.0.0" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" dependencies = [ "displaydoc", - "litemap 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "litemap 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", "serde", - "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", - "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", + "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", ] [[package]] name = "icu_locale_data" version = "2.0.0" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" [[package]] name = "icu_provider" version = "2.0.0" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" dependencies = [ "displaydoc", - "icu_locale_core 2.0.0 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "icu_locale_core 2.0.0 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", "serde", "stable_deref_trait", - "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", - "yoke 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", - "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", + "yoke 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", + "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", "zerotrie", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", ] [[package]] @@ -568,7 +568,7 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "ixdtf" version = "0.6.3" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" [[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=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" 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=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" dependencies = [ "serde_core", - "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", ] [[package]] @@ -870,7 +870,7 @@ dependencies = [ "num-traits", "temporal_rs", "timezone_provider", - "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", "zoneinfo64", ] @@ -887,9 +887,9 @@ dependencies = [ "num-traits", "resb", "timezone_provider", - "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", "web-time", - "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "writeable 0.6.1 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", "zoneinfo64", ] @@ -902,11 +902,11 @@ dependencies = [ "jiff-tzdb", "serde", "serde_json", - "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "tinystr 0.8.1 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", "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=0a2a4cdf)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", "zoneinfo64", "zoneinfo_rs", ] @@ -924,12 +924,12 @@ dependencies = [ [[package]] name = "tinystr" version = "0.8.1" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" dependencies = [ "databake", "displaydoc", "serde_core", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", ] [[package]] @@ -1234,7 +1234,7 @@ checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" [[package]] name = "writeable" version = "0.6.1" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" [[package]] name = "yoke" @@ -1251,11 +1251,11 @@ dependencies = [ [[package]] name = "yoke" version = "0.8.0" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" dependencies = [ "stable_deref_trait", - "yoke-derive 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", - "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "yoke-derive 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", + "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", ] [[package]] @@ -1273,7 +1273,7 @@ dependencies = [ [[package]] name = "yoke-derive" version = "0.8.0" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" 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=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" dependencies = [ - "zerofrom-derive 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "zerofrom-derive 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", ] [[package]] @@ -1313,7 +1313,7 @@ dependencies = [ [[package]] name = "zerofrom-derive" version = "0.1.6" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" 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=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" dependencies = [ "databake", "displaydoc", - "litemap 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "litemap 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", "serde_core", - "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "zerovec 0.11.4 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", ] [[package]] @@ -1345,19 +1345,19 @@ dependencies = [ [[package]] name = "zerovec" version = "0.11.4" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" dependencies = [ "databake", "serde", - "yoke 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", - "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf)", + "yoke 0.8.0 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", + "zerofrom 0.1.6 (git+https://github.com/unicode-org/icu4x?rev=eee59643)", "zerovec-derive", ] [[package]] name = "zerovec-derive" version = "0.11.1" -source = "git+https://github.com/unicode-org/icu4x?rev=0a2a4cdf#0a2a4cdf78beb466c083f143cae5514d8ee209d6" +source = "git+https://github.com/unicode-org/icu4x?rev=eee59643#eee596432397461a55d4c19844b67d927d45bfaa" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 373c9797f..ff380816d 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 = "0a2a4cdf" } -icu_calendar = { git = "https://github.com/unicode-org/icu4x", rev = "0a2a4cdf", default-features = false } -icu_locale = { git = "https://github.com/unicode-org/icu4x", rev = "0a2a4cdf" } +tinystr = { git = "https://github.com/unicode-org/icu4x", rev = "eee59643" } +icu_calendar = { git = "https://github.com/unicode-org/icu4x", rev = "eee59643", default-features = false } +icu_locale = { git = "https://github.com/unicode-org/icu4x", rev = "eee59643" } rustc-hash = "2.1.0" num-traits = { version = "0.2.19", default-features = false } -ixdtf = { git = "https://github.com/unicode-org/icu4x", rev = "0a2a4cdf" } +ixdtf = { git = "https://github.com/unicode-org/icu4x", rev = "eee59643" } 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 = "0a2a4cdf" } -databake = { git = "https://github.com/unicode-org/icu4x", rev = "0a2a4cdf" } -zerotrie = { git = "https://github.com/unicode-org/icu4x", rev = "0a2a4cdf" } -writeable = { git = "https://github.com/unicode-org/icu4x", rev = "0a2a4cdf" } +zerovec = { git = "https://github.com/unicode-org/icu4x", rev = "eee59643" } +databake = { git = "https://github.com/unicode-org/icu4x", rev = "eee59643" } +zerotrie = { git = "https://github.com/unicode-org/icu4x", rev = "eee59643" } +writeable = { git = "https://github.com/unicode-org/icu4x", rev = "eee59643" } zoneinfo64 = "0.2.0" # Diplomat diff --git a/src/builtins/core/calendar.rs b/src/builtins/core/calendar.rs index ddb30c407..3613f3bdb 100644 --- a/src/builtins/core/calendar.rs +++ b/src/builtins/core/calendar.rs @@ -15,7 +15,6 @@ use crate::{ }; use core::str::FromStr; -use core::num::NonZero; use icu_calendar::{ cal::{ Buddhist, Coptic, Ethiopian, EthiopianEraStyle, Hebrew, Hijri, Indian, Japanese, @@ -33,7 +32,6 @@ use icu_calendar::{ types::DateDuration as IcuDateDuration, types::DateDurationUnit as IcuUnit, types::DateFields, - types::MonthCode as IcuMonthCode, Gregorian, }; use icu_locale::extensions::unicode::Value; @@ -242,28 +240,13 @@ impl TryFrom for IcuUnit { impl<'a> TryFrom<&'a CalendarFields> for DateFields<'a> { type Error = TemporalError; fn try_from(other: &'a CalendarFields) -> TemporalResult { - let ordinal_month = other - .month - .map(|o| { - NonZero::new(o).ok_or( - TemporalError::range().with_message("Ordinal month must be positive integer"), - ) - }) - .transpose()?; - let day = other - .day - .map(|o| { - NonZero::new(o) - .ok_or(TemporalError::range().with_message("Day must be positive integer")) - }) - .transpose()?; let mut this = DateFields::default(); - this.era = other.era.as_deref(); + this.era = other.era.as_ref().map(|o| o.as_bytes()); this.era_year = other.era_year; this.extended_year = other.year; - this.month_code = other.month_code.map(|c| IcuMonthCode(c.0)); - this.ordinal_month = ordinal_month; - this.day = day; + this.month_code = other.month_code.as_ref().map(|o| o.0.as_bytes()); + this.ordinal_month = other.month; + this.day = other.day; Ok(this) } } @@ -369,8 +352,9 @@ impl Calendar { // So if a year was provided, we reresolve. if fields.era_year.is_some() || fields.extended_year.is_some() { let mut fields2 = DateFields::default(); - fields2.day = NonZero::new(self.0.day_of_month(&calendar_date).0); - fields2.month_code = Some(self.0.month(&calendar_date).standard_code); + fields2.day = Some(self.0.day_of_month(&calendar_date).0); + let code = self.0.month(&calendar_date).standard_code; + fields2.month_code = Some(code.0.as_bytes()); calendar_date = self.0.from_fields(fields2, options)?; } diff --git a/src/error.rs b/src/error.rs index 0e5847477..02eee85e3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,7 +4,8 @@ use core::fmt; use ixdtf::ParseError; use timezone_provider::TimeZoneProviderError; -use icu_calendar::{cal::AnyCalendarDifferenceError, DateError}; +use icu_calendar::cal::AnyCalendarDifferenceError; +use icu_calendar::error::{DateError, DateFromFieldsError, RangeError}; /// `TemporalError`'s error type. #[derive(Debug, Default, Clone, Copy, PartialEq)] @@ -149,12 +150,18 @@ impl fmt::Display for TemporalError { impl From for TemporalError { fn from(error: DateError) -> Self { - let kind = if error == DateError::NotEnoughFields { + TemporalError::range().with_enum(ErrorMessage::Icu4xDate(error)) + } +} + +impl From for TemporalError { + fn from(error: DateFromFieldsError) -> Self { + let kind = if error == DateFromFieldsError::NotEnoughFields { ErrorKind::Type } else { ErrorKind::Range }; - TemporalError::new(kind).with_enum(ErrorMessage::Icu4xDate(error)) + TemporalError::new(kind).with_enum(ErrorMessage::Icu4xDateFromFields(error)) } } @@ -218,6 +225,7 @@ pub(crate) enum ErrorMessage { String(&'static str), Ixdtf(ParseError), Icu4xDate(DateError), + Icu4xDateFromFields(DateFromFieldsError), Icu4xUntil(AnyCalendarDifferenceError), } @@ -264,18 +272,38 @@ impl ErrorMessage { Self::None => "", Self::String(s) => s, Self::Ixdtf(s) => ixdtf_error_to_static_string(s), - Self::Icu4xDate(DateError::Range { field, .. }) => match field { - "year" => "Year out of range.", - "month" => "Month out of range.", - "day" => "Day out of range.", - _ => "Field out of range.", - }, - Self::Icu4xDate(DateError::UnknownEra) => "Unknown era.", + Self::Icu4xDate(DateError::Range { field, .. }) + | Self::Icu4xDateFromFields(DateFromFieldsError::Range(RangeError { field, .. })) => { + match field { + "year" => "Year out of range.", + "month" => "Month out of range.", + "day" => "Day out of range.", + _ => "Field out of range.", + } + } + Self::Icu4xDate(DateError::UnknownEra) + | Self::Icu4xDateFromFields(DateFromFieldsError::UnknownEra) => "Unknown era.", Self::Icu4xDate(DateError::UnknownMonthCode(..)) => "Unknown month code.", - Self::Icu4xDate(DateError::InconsistentYear) => "Inconsistent year.", - Self::Icu4xDate(DateError::InconsistentMonth) => "Inconsistent month/monthCode.", - Self::Icu4xDate(DateError::NotEnoughFields) => "Insufficient fields.", + Self::Icu4xDateFromFields(DateFromFieldsError::MonthCodeInvalidSyntax) => { + "Invalid month code." + } + Self::Icu4xDateFromFields(DateFromFieldsError::MonthCodeNotInCalendar) => { + "Month code not in calendar." + } + Self::Icu4xDateFromFields(DateFromFieldsError::MonthCodeNotInYear) => { + "Month code not in year." + } + Self::Icu4xDateFromFields(DateFromFieldsError::InconsistentYear) => { + "Inconsistent year." + } + Self::Icu4xDateFromFields(DateFromFieldsError::InconsistentMonth) => { + "Inconsistent month/monthCode." + } + Self::Icu4xDateFromFields(DateFromFieldsError::NotEnoughFields) => { + "Insufficient fields." + } Self::Icu4xDate(_) => "Date error.", + Self::Icu4xDateFromFields(_) => "Date error.", Self::Icu4xUntil(AnyCalendarDifferenceError::MismatchedCalendars) => { "Mismatched calendars." }