From 0e10a516f7035b3eac412fa4272b9c21222466ec Mon Sep 17 00:00:00 2001 From: atcupps Date: Mon, 26 Jun 2023 14:59:37 -0700 Subject: [PATCH 1/4] Add `FormattableYear` field `cyclic` --- components/calendar/src/buddhist.rs | 1 + components/calendar/src/coptic.rs | 2 ++ components/calendar/src/ethiopian.rs | 3 +++ components/calendar/src/gregorian.rs | 2 ++ components/calendar/src/indian.rs | 3 +++ components/calendar/src/iso.rs | 1 + components/calendar/src/japanese.rs | 1 + components/calendar/src/persian.rs | 1 + components/calendar/src/types.rs | 10 ++++++---- 9 files changed, 20 insertions(+), 4 deletions(-) diff --git a/components/calendar/src/buddhist.rs b/components/calendar/src/buddhist.rs index 0b309104927..0a49f51a5ec 100644 --- a/components/calendar/src/buddhist.rs +++ b/components/calendar/src/buddhist.rs @@ -216,6 +216,7 @@ fn iso_year_as_buddhist(year: i32) -> types::FormattableYear { types::FormattableYear { era: types::Era(tinystr!(16, "be")), number: buddhist_year, + cyclic: 0, related_iso: None, } } diff --git a/components/calendar/src/coptic.rs b/components/calendar/src/coptic.rs index 905b840f53e..b2e58f40386 100644 --- a/components/calendar/src/coptic.rs +++ b/components/calendar/src/coptic.rs @@ -326,12 +326,14 @@ fn year_as_coptic(year: i32) -> types::FormattableYear { types::FormattableYear { era: types::Era(tinystr!(16, "ad")), number: year, + cyclic: 0, related_iso: None, } } else { types::FormattableYear { era: types::Era(tinystr!(16, "bd")), number: 1 - year, + cyclic: 0, related_iso: None, } } diff --git a/components/calendar/src/ethiopian.rs b/components/calendar/src/ethiopian.rs index 25b22a5cb6a..1e1723c7cc3 100644 --- a/components/calendar/src/ethiopian.rs +++ b/components/calendar/src/ethiopian.rs @@ -292,18 +292,21 @@ impl Ethiopian { types::FormattableYear { era: types::Era(tinystr!(16, "mundi")), number: year + AMETE_ALEM_OFFSET, + cyclic: 0, related_iso: None, } } else if year > 0 { types::FormattableYear { era: types::Era(tinystr!(16, "incar")), number: year, + cyclic: 0, related_iso: None, } } else { types::FormattableYear { era: types::Era(tinystr!(16, "pre-incar")), number: 1 - year, + cyclic: 0, related_iso: None, } } diff --git a/components/calendar/src/gregorian.rs b/components/calendar/src/gregorian.rs index 7bdac5dc54c..3e418d23ef8 100644 --- a/components/calendar/src/gregorian.rs +++ b/components/calendar/src/gregorian.rs @@ -223,12 +223,14 @@ pub(crate) fn year_as_gregorian(year: i32) -> types::FormattableYear { types::FormattableYear { era: types::Era(tinystr!(16, "ce")), number: year, + cyclic: 0, related_iso: None, } } else { types::FormattableYear { era: types::Era(tinystr!(16, "bce")), number: 1_i32.saturating_sub(year), + cyclic: 0, related_iso: None, } } diff --git a/components/calendar/src/indian.rs b/components/calendar/src/indian.rs index 63a606f87e9..6cee39d0389 100644 --- a/components/calendar/src/indian.rs +++ b/components/calendar/src/indian.rs @@ -188,6 +188,7 @@ impl Calendar for Indian { types::FormattableYear { era: types::Era(tinystr!(16, "saka")), number: date.0.year, + cyclic: 0, related_iso: None, } } @@ -204,11 +205,13 @@ impl Calendar for Indian { let prev_year = types::FormattableYear { era: types::Era(tinystr!(16, "saka")), number: date.0.year - 1, + cyclic: 0, related_iso: None, }; let next_year = types::FormattableYear { era: types::Era(tinystr!(16, "saka")), number: date.0.year + 1, + cyclic: 0, related_iso: None, }; types::DayOfYearInfo { diff --git a/components/calendar/src/iso.rs b/components/calendar/src/iso.rs index 35670970737..861df36fc0a 100644 --- a/components/calendar/src/iso.rs +++ b/components/calendar/src/iso.rs @@ -516,6 +516,7 @@ impl Iso { types::FormattableYear { era: types::Era(tinystr!(16, "default")), number: year, + cyclic: 0, related_iso: None, } } diff --git a/components/calendar/src/japanese.rs b/components/calendar/src/japanese.rs index 60e7191f191..b43cfc79344 100644 --- a/components/calendar/src/japanese.rs +++ b/components/calendar/src/japanese.rs @@ -272,6 +272,7 @@ impl Calendar for Japanese { types::FormattableYear { era: types::Era(date.era), number: date.adjusted_year, + cyclic: 0, related_iso: None, } } diff --git a/components/calendar/src/persian.rs b/components/calendar/src/persian.rs index e8dafca14c3..5783cc552e5 100644 --- a/components/calendar/src/persian.rs +++ b/components/calendar/src/persian.rs @@ -298,6 +298,7 @@ impl Persian { types::FormattableYear { era: types::Era(tinystr!(16, "ah")), number: year, + cyclic: 0, related_iso: None, } } diff --git a/components/calendar/src/types.rs b/components/calendar/src/types.rs index b117eda48e3..2b5e3e2bc6a 100644 --- a/components/calendar/src/types.rs +++ b/components/calendar/src/types.rs @@ -37,9 +37,6 @@ impl FromStr for Era { } /// Representation of a formattable year. -/// -/// More fields may be added in the future, for things like -/// the cyclic or extended year #[derive(Copy, Clone, Debug, PartialEq)] #[non_exhaustive] pub struct FormattableYear { @@ -49,6 +46,10 @@ pub struct FormattableYear { /// The year number in the current era (usually 1-based). pub number: i32, + /// The year in the current cycle for cyclic calendars; + /// can be ignored and set to any value for non-cyclic calendars. + pub cyclic: i32, + /// The related ISO year. This is normally the ISO (proleptic Gregorian) year having the greatest /// overlap with the calendar year. It is used in certain date formatting patterns. /// @@ -62,10 +63,11 @@ impl FormattableYear { /// /// Other fields can be set mutably after construction /// as needed - pub fn new(era: Era, number: i32) -> Self { + pub fn new(era: Era, number: i32, cyclic: i32) -> Self { Self { era, number, + cyclic, related_iso: None, } } From 7e2bc9200875a74068f7ab98ce9623cb2822492b Mon Sep 17 00:00:00 2001 From: atcupps Date: Tue, 27 Jun 2023 07:57:16 -0700 Subject: [PATCH 2/4] Make field `cyclic` in `FormattableYear` an `Option` --- components/calendar/src/buddhist.rs | 2 +- components/calendar/src/coptic.rs | 4 ++-- components/calendar/src/ethiopian.rs | 6 +++--- components/calendar/src/gregorian.rs | 4 ++-- components/calendar/src/indian.rs | 6 +++--- components/calendar/src/iso.rs | 2 +- components/calendar/src/japanese.rs | 2 +- components/calendar/src/persian.rs | 2 +- components/calendar/src/types.rs | 4 ++-- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/components/calendar/src/buddhist.rs b/components/calendar/src/buddhist.rs index 0a49f51a5ec..8b44473704a 100644 --- a/components/calendar/src/buddhist.rs +++ b/components/calendar/src/buddhist.rs @@ -216,7 +216,7 @@ fn iso_year_as_buddhist(year: i32) -> types::FormattableYear { types::FormattableYear { era: types::Era(tinystr!(16, "be")), number: buddhist_year, - cyclic: 0, + cyclic: None, related_iso: None, } } diff --git a/components/calendar/src/coptic.rs b/components/calendar/src/coptic.rs index b2e58f40386..05344a43a9a 100644 --- a/components/calendar/src/coptic.rs +++ b/components/calendar/src/coptic.rs @@ -326,14 +326,14 @@ fn year_as_coptic(year: i32) -> types::FormattableYear { types::FormattableYear { era: types::Era(tinystr!(16, "ad")), number: year, - cyclic: 0, + cyclic: None, related_iso: None, } } else { types::FormattableYear { era: types::Era(tinystr!(16, "bd")), number: 1 - year, - cyclic: 0, + cyclic: None, related_iso: None, } } diff --git a/components/calendar/src/ethiopian.rs b/components/calendar/src/ethiopian.rs index 1e1723c7cc3..7429395d21d 100644 --- a/components/calendar/src/ethiopian.rs +++ b/components/calendar/src/ethiopian.rs @@ -292,21 +292,21 @@ impl Ethiopian { types::FormattableYear { era: types::Era(tinystr!(16, "mundi")), number: year + AMETE_ALEM_OFFSET, - cyclic: 0, + cyclic: None, related_iso: None, } } else if year > 0 { types::FormattableYear { era: types::Era(tinystr!(16, "incar")), number: year, - cyclic: 0, + cyclic: None, related_iso: None, } } else { types::FormattableYear { era: types::Era(tinystr!(16, "pre-incar")), number: 1 - year, - cyclic: 0, + cyclic: None, related_iso: None, } } diff --git a/components/calendar/src/gregorian.rs b/components/calendar/src/gregorian.rs index 3e418d23ef8..03f96b58c67 100644 --- a/components/calendar/src/gregorian.rs +++ b/components/calendar/src/gregorian.rs @@ -223,14 +223,14 @@ pub(crate) fn year_as_gregorian(year: i32) -> types::FormattableYear { types::FormattableYear { era: types::Era(tinystr!(16, "ce")), number: year, - cyclic: 0, + cyclic: None, related_iso: None, } } else { types::FormattableYear { era: types::Era(tinystr!(16, "bce")), number: 1_i32.saturating_sub(year), - cyclic: 0, + cyclic: None, related_iso: None, } } diff --git a/components/calendar/src/indian.rs b/components/calendar/src/indian.rs index 6cee39d0389..9f50a050795 100644 --- a/components/calendar/src/indian.rs +++ b/components/calendar/src/indian.rs @@ -188,7 +188,7 @@ impl Calendar for Indian { types::FormattableYear { era: types::Era(tinystr!(16, "saka")), number: date.0.year, - cyclic: 0, + cyclic: None, related_iso: None, } } @@ -205,13 +205,13 @@ impl Calendar for Indian { let prev_year = types::FormattableYear { era: types::Era(tinystr!(16, "saka")), number: date.0.year - 1, - cyclic: 0, + cyclic: None, related_iso: None, }; let next_year = types::FormattableYear { era: types::Era(tinystr!(16, "saka")), number: date.0.year + 1, - cyclic: 0, + cyclic: None, related_iso: None, }; types::DayOfYearInfo { diff --git a/components/calendar/src/iso.rs b/components/calendar/src/iso.rs index 861df36fc0a..1475413c91b 100644 --- a/components/calendar/src/iso.rs +++ b/components/calendar/src/iso.rs @@ -516,7 +516,7 @@ impl Iso { types::FormattableYear { era: types::Era(tinystr!(16, "default")), number: year, - cyclic: 0, + cyclic: None, related_iso: None, } } diff --git a/components/calendar/src/japanese.rs b/components/calendar/src/japanese.rs index b43cfc79344..7127a00c58c 100644 --- a/components/calendar/src/japanese.rs +++ b/components/calendar/src/japanese.rs @@ -272,7 +272,7 @@ impl Calendar for Japanese { types::FormattableYear { era: types::Era(date.era), number: date.adjusted_year, - cyclic: 0, + cyclic: None, related_iso: None, } } diff --git a/components/calendar/src/persian.rs b/components/calendar/src/persian.rs index 5783cc552e5..fb3e8578cab 100644 --- a/components/calendar/src/persian.rs +++ b/components/calendar/src/persian.rs @@ -298,7 +298,7 @@ impl Persian { types::FormattableYear { era: types::Era(tinystr!(16, "ah")), number: year, - cyclic: 0, + cyclic: None, related_iso: None, } } diff --git a/components/calendar/src/types.rs b/components/calendar/src/types.rs index 2b5e3e2bc6a..b4db3a454e8 100644 --- a/components/calendar/src/types.rs +++ b/components/calendar/src/types.rs @@ -48,7 +48,7 @@ pub struct FormattableYear { /// The year in the current cycle for cyclic calendars; /// can be ignored and set to any value for non-cyclic calendars. - pub cyclic: i32, + pub cyclic: Option, /// The related ISO year. This is normally the ISO (proleptic Gregorian) year having the greatest /// overlap with the calendar year. It is used in certain date formatting patterns. @@ -63,7 +63,7 @@ impl FormattableYear { /// /// Other fields can be set mutably after construction /// as needed - pub fn new(era: Era, number: i32, cyclic: i32) -> Self { + pub fn new(era: Era, number: i32, cyclic: Option) -> Self { Self { era, number, From 12b68438b11efbb7ed8f2240ab75214ac4dfc224 Mon Sep 17 00:00:00 2001 From: atcupps Date: Tue, 27 Jun 2023 07:58:39 -0700 Subject: [PATCH 3/4] Add comments --- components/calendar/src/types.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/calendar/src/types.rs b/components/calendar/src/types.rs index b4db3a454e8..94194a618fb 100644 --- a/components/calendar/src/types.rs +++ b/components/calendar/src/types.rs @@ -37,6 +37,8 @@ impl FromStr for Era { } /// Representation of a formattable year. +/// +/// More fields may be added in the future for things like extended year #[derive(Copy, Clone, Debug, PartialEq)] #[non_exhaustive] pub struct FormattableYear { @@ -47,7 +49,7 @@ pub struct FormattableYear { pub number: i32, /// The year in the current cycle for cyclic calendars; - /// can be ignored and set to any value for non-cyclic calendars. + /// can be set to None for non-cyclic calendars pub cyclic: Option, /// The related ISO year. This is normally the ISO (proleptic Gregorian) year having the greatest From 5cd3d79c2a097bc752ec0024cc8d8057db759cc9 Mon Sep 17 00:00:00 2001 From: atcupps Date: Tue, 27 Jun 2023 11:31:59 -0700 Subject: [PATCH 4/4] Changed test size of --- components/datetime/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/datetime/src/lib.rs b/components/datetime/src/lib.rs index c7d37eb2f9d..33df4a0f759 100644 --- a/components/datetime/src/lib.rs +++ b/components/datetime/src/lib.rs @@ -216,9 +216,9 @@ mod tests { check_size_of!(6744 | 5408, TypedDateTimeFormatter::); check_size_of!(88, DateTimeError); - check_size_of!(176, FormattedDateTime); + check_size_of!(200, FormattedDateTime); check_size_of!(16, FormattedTimeZone::); - check_size_of!(160, FormattedZonedDateTime); + check_size_of!(184, FormattedZonedDateTime); check_size_of!(13, DateTimeFormatterOptions); type DP = DataPayload;