diff --git a/CHANGELOG.md b/CHANGELOG.md index 7368905f5f..46b723bcf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - `icu_calendar` - Consistently name calendar-specific `Date`/`DateTime` functions that have a calendar argument (https://github.com/unicode-org/icu4x/pull/5692) - Move all calendar types to `cal` module (https://github.com/unicode-org/icu4x/pull/5701) + - Shorten integer types returned by `day_of_month()`, `week_of_month()`, and `week_of_year()` to `u8` (https://github.com/unicode-org/icu4x/pull/5702) - `icu_collections` - `icu_normalizer` - `icu_datetime` diff --git a/components/calendar/src/any_calendar.rs b/components/calendar/src/any_calendar.rs index 232c9bc76c..c1a15b9848 100644 --- a/components/calendar/src/any_calendar.rs +++ b/components/calendar/src/any_calendar.rs @@ -1864,7 +1864,6 @@ mod tests { use super::*; use crate::Ref; - use core::convert::TryInto; fn single_test_roundtrip( calendar: Ref, @@ -1889,7 +1888,7 @@ mod tests { let roundtrip_era = roundtrip_year.formatting_era().unwrap_or(era); let roundtrip_year = roundtrip_year.era_year_or_extended(); let roundtrip_month = date.month().standard_code; - let roundtrip_day = date.day_of_month().0.try_into().expect("Must fit in u8"); + let roundtrip_day = date.day_of_month().0; assert_eq!( (era, year, month, day), diff --git a/components/calendar/src/buddhist.rs b/components/calendar/src/buddhist.rs index f889d45ce5..be399d8f05 100644 --- a/components/calendar/src/buddhist.rs +++ b/components/calendar/src/buddhist.rs @@ -342,7 +342,7 @@ mod test { ); assert_eq!( buddhist1.day_of_month().0, - buddhist_day as u32, + buddhist_day, "Iso -> Buddhist day check failed for case: {case:?}" ); @@ -361,7 +361,7 @@ mod test { ); assert_eq!( iso2.day_of_month().0, - iso_day as u32, + iso_day, "Buddhist -> Iso day check failed for case: {case:?}" ); } diff --git a/components/calendar/src/calendar_arithmetic.rs b/components/calendar/src/calendar_arithmetic.rs index 15edd8ca93..2bd38cb3db 100644 --- a/components/calendar/src/calendar_arithmetic.rs +++ b/components/calendar/src/calendar_arithmetic.rs @@ -300,7 +300,7 @@ impl ArithmeticDate { #[inline] pub fn day_of_month(&self) -> types::DayOfMonth { - types::DayOfMonth(self.day.into()) + types::DayOfMonth(self.day) } /// The [`types::MonthInfo`] for the current month (with month code) for a solar calendar diff --git a/components/calendar/src/chinese.rs b/components/calendar/src/chinese.rs index 4ad5659957..bb9622aec2 100644 --- a/components/calendar/src/chinese.rs +++ b/components/calendar/src/chinese.rs @@ -285,7 +285,7 @@ impl Calendar for Chinese { /// The calendar-specific day-of-month represented by `date` fn day_of_month(&self, date: &Self::DateInner) -> types::DayOfMonth { - types::DayOfMonth(date.0 .0.day as u32) + types::DayOfMonth(date.0 .0.day) } /// Information of the day of the year @@ -666,7 +666,7 @@ mod test { iso_day: u8, expected_year: i32, expected_month: u8, - expected_day: u32, + expected_day: u8, } let cases = [ @@ -1006,7 +1006,7 @@ mod test { expected_rel_iso: i32, expected_cyclic: u8, expected_month: u8, - expected_day: u32, + expected_day: u8, } let cases = [ diff --git a/components/calendar/src/dangi.rs b/components/calendar/src/dangi.rs index fe7dda0a97..d2c0b708c6 100644 --- a/components/calendar/src/dangi.rs +++ b/components/calendar/src/dangi.rs @@ -266,7 +266,7 @@ impl Calendar for Dangi { } fn day_of_month(&self, date: &Self::DateInner) -> crate::types::DayOfMonth { - types::DayOfMonth(date.0 .0.day as u32) + types::DayOfMonth(date.0 .0.day) } fn day_of_year_info(&self, date: &Self::DateInner) -> crate::types::DayOfYearInfo { @@ -492,7 +492,7 @@ mod test { expected_rel_iso: i32, expected_cyclic: u8, expected_month: u8, - expected_day: u32, + expected_day: u8, } let cases = [ diff --git a/components/calendar/src/gregorian.rs b/components/calendar/src/gregorian.rs index b948066683..e0e3ac26cb 100644 --- a/components/calendar/src/gregorian.rs +++ b/components/calendar/src/gregorian.rs @@ -374,7 +374,7 @@ mod test { expected_year: i32, expected_era: Era, expected_month: u8, - expected_day: u32, + expected_day: u8, } fn check_test_case(case: TestCase) { diff --git a/components/calendar/src/indian.rs b/components/calendar/src/indian.rs index db220014a9..72681c2f03 100644 --- a/components/calendar/src/indian.rs +++ b/components/calendar/src/indian.rs @@ -329,7 +329,7 @@ mod tests { "{y}-{m}-{d}: ISO month did not match" ); assert_eq!( - iso.day_of_month().0 as u8, + iso.day_of_month().0, iso_d, "{y}-{m}-{d}: ISO day did not match" ); @@ -376,7 +376,7 @@ mod tests { iso_day: u8, expected_year: i32, expected_month: u8, - expected_day: u32, + expected_day: u8, } fn check_case(case: TestCase) { diff --git a/components/calendar/src/julian.rs b/components/calendar/src/julian.rs index 15500a24e6..036f9f798a 100644 --- a/components/calendar/src/julian.rs +++ b/components/calendar/src/julian.rs @@ -420,7 +420,7 @@ mod test { expected_year: i32, expected_era: Era, expected_month: u8, - expected_day: u32, + expected_day: u8, } let cases = [ diff --git a/components/calendar/src/persian.rs b/components/calendar/src/persian.rs index 7a1b615ea7..bd785d229f 100644 --- a/components/calendar/src/persian.rs +++ b/components/calendar/src/persian.rs @@ -534,7 +534,7 @@ mod tests { // From https://calendar.ut.ac.ir/Fa/News/Data/Doc/KabiseShamsi1206-1498-new.pdf // Plain text version at https://github.com/roozbehp/persiancalendar/blob/main/kabise.txt - static CALENDAR_UT_AC_IR_TEST_DATA: [(i32, bool, i32, u8, u32); 293] = [ + static CALENDAR_UT_AC_IR_TEST_DATA: [(i32, bool, i32, u8, u8); 293] = [ (1206, false, 1827, 3, 22), (1207, false, 1828, 3, 21), (1208, false, 1829, 3, 21), diff --git a/components/calendar/src/roc.rs b/components/calendar/src/roc.rs index dcb3ff3e13..6fbfd9eaa0 100644 --- a/components/calendar/src/roc.rs +++ b/components/calendar/src/roc.rs @@ -300,7 +300,7 @@ mod test { expected_year: i32, expected_era: Era, expected_month: u8, - expected_day: u32, + expected_day: u8, } fn check_test_case(case: TestCase) { diff --git a/components/calendar/src/types.rs b/components/calendar/src/types.rs index ec87545f5a..7e18d35c93 100644 --- a/components/calendar/src/types.rs +++ b/components/calendar/src/types.rs @@ -331,22 +331,22 @@ pub struct DayOfYearInfo { /// A day number in a month. Usually 1-based. #[allow(clippy::exhaustive_structs)] // this is a newtype #[derive(Clone, Copy, Debug, PartialEq)] -pub struct DayOfMonth(pub u32); +pub struct DayOfMonth(pub u8); /// A week number in a month. Usually 1-based. #[derive(Clone, Copy, Debug, PartialEq)] #[allow(clippy::exhaustive_structs)] // this is a newtype -pub struct WeekOfMonth(pub u32); +pub struct WeekOfMonth(pub u8); /// A week number in a year. Usually 1-based. #[derive(Clone, Copy, Debug, PartialEq)] #[allow(clippy::exhaustive_structs)] // this is a newtype -pub struct WeekOfYear(pub u32); +pub struct WeekOfYear(pub u8); /// A day of week in month. 1-based. #[derive(Clone, Copy, Debug, PartialEq)] #[allow(clippy::exhaustive_structs)] // this is a newtype -pub struct DayOfWeekInMonth(pub u32); +pub struct DayOfWeekInMonth(pub u8); impl From for DayOfWeekInMonth { fn from(day_of_month: DayOfMonth) -> Self { diff --git a/components/calendar/src/week_of.rs b/components/calendar/src/week_of.rs index 1128d3a632..1536e906a9 100644 --- a/components/calendar/src/week_of.rs +++ b/components/calendar/src/week_of.rs @@ -84,7 +84,11 @@ impl WeekCalculator { /// /// [1]: https://www.unicode.org/reports/tr35/tr35-55/tr35-dates.html#Date_Patterns_Week_Of_Year pub fn week_of_month(&self, day_of_month: DayOfMonth, iso_weekday: IsoWeekday) -> WeekOfMonth { - WeekOfMonth(simple_week_of(self.first_weekday, day_of_month.0 as u16, iso_weekday) as u32) + WeekOfMonth(simple_week_of( + self.first_weekday, + day_of_month.0 as u16, + iso_weekday, + )) } /// Returns the week of year according to the weekday and [`DayOfYearInfo`]. @@ -169,7 +173,7 @@ enum RelativeWeek { /// A week that is assigned to the last week of the previous year/month. e.g. 2021-01-01 is week 54 of 2020 per the ISO calendar. LastWeekOfPreviousUnit, /// A week that's assigned to the current year/month. The offset is 1-based. e.g. 2021-01-11 is week 2 of 2021 per the ISO calendar so would be WeekOfCurrentUnit(2). - WeekOfCurrentUnit(u16), + WeekOfCurrentUnit(u8), /// A week that is assigned to the first week of the next year/month. e.g. 2019-12-31 is week 1 of 2020 per the ISO calendar. FirstWeekOfNextUnit, } @@ -213,7 +217,7 @@ impl UnitInfo { } /// Returns the number of weeks in this unit according to `calendar`. - fn num_weeks(&self, calendar: &WeekCalculator) -> u16 { + fn num_weeks(&self, calendar: &WeekCalculator) -> u8 { let first_week_offset = self.first_week_offset(calendar); let num_days_including_first_week = (self.duration_days as i32) - (first_week_offset as i32); @@ -221,7 +225,7 @@ impl UnitInfo { num_days_including_first_week >= 0, "Unit is shorter than a week." ); - ((num_days_including_first_week + 7 - (calendar.min_week_days as i32)) / 7) as u16 + ((num_days_including_first_week + 7 - (calendar.min_week_days as i32)) / 7) as u8 } /// Returns the week number for the given day in this unit. @@ -232,7 +236,7 @@ impl UnitInfo { return RelativeWeek::LastWeekOfPreviousUnit; } - let week_number = (1 + days_since_first_week / 7) as u16; + let week_number = (1 + days_since_first_week / 7) as u8; if week_number > self.num_weeks(calendar) { return RelativeWeek::FirstWeekOfNextUnit; } @@ -257,7 +261,7 @@ pub enum RelativeUnit { #[allow(clippy::exhaustive_structs)] // this type is stable pub struct WeekOf { /// Week of month/year. 1 based. - pub week: u16, + pub week: u8, /// The month/year that this week is in, relative to the month/year of the input date. pub unit: RelativeUnit, } @@ -316,7 +320,7 @@ pub fn week_of( /// - first_weekday: The first day of a week. /// - day: 1-based day of the month or year. /// - week_day: The weekday of `day`. -pub fn simple_week_of(first_weekday: IsoWeekday, day: u16, week_day: IsoWeekday) -> u16 { +pub fn simple_week_of(first_weekday: IsoWeekday, day: u16, week_day: IsoWeekday) -> u8 { let calendar = WeekCalculator { first_weekday, min_week_days: 1, diff --git a/ffi/capi/bindings/c/Date.h b/ffi/capi/bindings/c/Date.h index 69b461fcf9..38ba240d9b 100644 --- a/ffi/capi/bindings/c/Date.h +++ b/ffi/capi/bindings/c/Date.h @@ -37,11 +37,11 @@ IsoDate* icu4x_Date_to_iso_mv1(const Date* self); uint16_t icu4x_Date_day_of_year_mv1(const Date* self); -uint32_t icu4x_Date_day_of_month_mv1(const Date* self); +uint8_t icu4x_Date_day_of_month_mv1(const Date* self); IsoWeekday icu4x_Date_day_of_week_mv1(const Date* self); -uint32_t icu4x_Date_week_of_month_mv1(const Date* self, IsoWeekday first_weekday); +uint8_t icu4x_Date_week_of_month_mv1(const Date* self, IsoWeekday first_weekday); WeekOf icu4x_Date_week_of_year_mv1(const Date* self, const WeekCalculator* calculator); diff --git a/ffi/capi/bindings/c/DateTime.h b/ffi/capi/bindings/c/DateTime.h index 6e269bf85c..5067ce553b 100644 --- a/ffi/capi/bindings/c/DateTime.h +++ b/ffi/capi/bindings/c/DateTime.h @@ -53,11 +53,11 @@ uint32_t icu4x_DateTime_nanosecond_mv1(const DateTime* self); uint16_t icu4x_DateTime_day_of_year_mv1(const DateTime* self); -uint32_t icu4x_DateTime_day_of_month_mv1(const DateTime* self); +uint8_t icu4x_DateTime_day_of_month_mv1(const DateTime* self); IsoWeekday icu4x_DateTime_day_of_week_mv1(const DateTime* self); -uint32_t icu4x_DateTime_week_of_month_mv1(const DateTime* self, IsoWeekday first_weekday); +uint8_t icu4x_DateTime_week_of_month_mv1(const DateTime* self, IsoWeekday first_weekday); WeekOf icu4x_DateTime_week_of_year_mv1(const DateTime* self, const WeekCalculator* calculator); diff --git a/ffi/capi/bindings/c/IsoDate.h b/ffi/capi/bindings/c/IsoDate.h index 9c155e6407..ae7aefcdd5 100644 --- a/ffi/capi/bindings/c/IsoDate.h +++ b/ffi/capi/bindings/c/IsoDate.h @@ -36,11 +36,11 @@ Date* icu4x_IsoDate_to_any_mv1(const IsoDate* self); uint16_t icu4x_IsoDate_day_of_year_mv1(const IsoDate* self); -uint32_t icu4x_IsoDate_day_of_month_mv1(const IsoDate* self); +uint8_t icu4x_IsoDate_day_of_month_mv1(const IsoDate* self); IsoWeekday icu4x_IsoDate_day_of_week_mv1(const IsoDate* self); -uint32_t icu4x_IsoDate_week_of_month_mv1(const IsoDate* self, IsoWeekday first_weekday); +uint8_t icu4x_IsoDate_week_of_month_mv1(const IsoDate* self, IsoWeekday first_weekday); WeekOf icu4x_IsoDate_week_of_year_mv1(const IsoDate* self, const WeekCalculator* calculator); diff --git a/ffi/capi/bindings/c/IsoDateTime.h b/ffi/capi/bindings/c/IsoDateTime.h index eea402c69c..c47bbe08b2 100644 --- a/ffi/capi/bindings/c/IsoDateTime.h +++ b/ffi/capi/bindings/c/IsoDateTime.h @@ -56,11 +56,11 @@ uint32_t icu4x_IsoDateTime_nanosecond_mv1(const IsoDateTime* self); uint16_t icu4x_IsoDateTime_day_of_year_mv1(const IsoDateTime* self); -uint32_t icu4x_IsoDateTime_day_of_month_mv1(const IsoDateTime* self); +uint8_t icu4x_IsoDateTime_day_of_month_mv1(const IsoDateTime* self); IsoWeekday icu4x_IsoDateTime_day_of_week_mv1(const IsoDateTime* self); -uint32_t icu4x_IsoDateTime_week_of_month_mv1(const IsoDateTime* self, IsoWeekday first_weekday); +uint8_t icu4x_IsoDateTime_week_of_month_mv1(const IsoDateTime* self, IsoWeekday first_weekday); WeekOf icu4x_IsoDateTime_week_of_year_mv1(const IsoDateTime* self, const WeekCalculator* calculator); diff --git a/ffi/capi/bindings/c/WeekOf.d.h b/ffi/capi/bindings/c/WeekOf.d.h index 5217a03fd3..aa4af9555a 100644 --- a/ffi/capi/bindings/c/WeekOf.d.h +++ b/ffi/capi/bindings/c/WeekOf.d.h @@ -13,7 +13,7 @@ typedef struct WeekOf { - uint16_t week; + uint8_t week; WeekRelativeUnit unit; } WeekOf; diff --git a/ffi/capi/bindings/cpp/icu4x/Date.d.hpp b/ffi/capi/bindings/cpp/icu4x/Date.d.hpp index 0a22c47660..534170ca60 100644 --- a/ffi/capi/bindings/cpp/icu4x/Date.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/Date.d.hpp @@ -47,11 +47,11 @@ class Date { inline uint16_t day_of_year() const; - inline uint32_t day_of_month() const; + inline uint8_t day_of_month() const; inline icu4x::IsoWeekday day_of_week() const; - inline uint32_t week_of_month(icu4x::IsoWeekday first_weekday) const; + inline uint8_t week_of_month(icu4x::IsoWeekday first_weekday) const; inline icu4x::WeekOf week_of_year(const icu4x::WeekCalculator& calculator) const; diff --git a/ffi/capi/bindings/cpp/icu4x/Date.hpp b/ffi/capi/bindings/cpp/icu4x/Date.hpp index 0e96996e9f..ad8c2a162e 100644 --- a/ffi/capi/bindings/cpp/icu4x/Date.hpp +++ b/ffi/capi/bindings/cpp/icu4x/Date.hpp @@ -38,11 +38,11 @@ namespace capi { uint16_t icu4x_Date_day_of_year_mv1(const icu4x::capi::Date* self); - uint32_t icu4x_Date_day_of_month_mv1(const icu4x::capi::Date* self); + uint8_t icu4x_Date_day_of_month_mv1(const icu4x::capi::Date* self); icu4x::capi::IsoWeekday icu4x_Date_day_of_week_mv1(const icu4x::capi::Date* self); - uint32_t icu4x_Date_week_of_month_mv1(const icu4x::capi::Date* self, icu4x::capi::IsoWeekday first_weekday); + uint8_t icu4x_Date_week_of_month_mv1(const icu4x::capi::Date* self, icu4x::capi::IsoWeekday first_weekday); icu4x::capi::WeekOf icu4x_Date_week_of_year_mv1(const icu4x::capi::Date* self, const icu4x::capi::WeekCalculator* calculator); @@ -113,7 +113,7 @@ inline uint16_t icu4x::Date::day_of_year() const { return result; } -inline uint32_t icu4x::Date::day_of_month() const { +inline uint8_t icu4x::Date::day_of_month() const { auto result = icu4x::capi::icu4x_Date_day_of_month_mv1(this->AsFFI()); return result; } @@ -123,7 +123,7 @@ inline icu4x::IsoWeekday icu4x::Date::day_of_week() const { return icu4x::IsoWeekday::FromFFI(result); } -inline uint32_t icu4x::Date::week_of_month(icu4x::IsoWeekday first_weekday) const { +inline uint8_t icu4x::Date::week_of_month(icu4x::IsoWeekday first_weekday) const { auto result = icu4x::capi::icu4x_Date_week_of_month_mv1(this->AsFFI(), first_weekday.AsFFI()); return result; diff --git a/ffi/capi/bindings/cpp/icu4x/DateTime.d.hpp b/ffi/capi/bindings/cpp/icu4x/DateTime.d.hpp index 3f064030b0..d13ffd373c 100644 --- a/ffi/capi/bindings/cpp/icu4x/DateTime.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/DateTime.d.hpp @@ -65,11 +65,11 @@ class DateTime { inline uint16_t day_of_year() const; - inline uint32_t day_of_month() const; + inline uint8_t day_of_month() const; inline icu4x::IsoWeekday day_of_week() const; - inline uint32_t week_of_month(icu4x::IsoWeekday first_weekday) const; + inline uint8_t week_of_month(icu4x::IsoWeekday first_weekday) const; inline icu4x::WeekOf week_of_year(const icu4x::WeekCalculator& calculator) const; diff --git a/ffi/capi/bindings/cpp/icu4x/DateTime.hpp b/ffi/capi/bindings/cpp/icu4x/DateTime.hpp index 1d1a36902b..e23c8a070b 100644 --- a/ffi/capi/bindings/cpp/icu4x/DateTime.hpp +++ b/ffi/capi/bindings/cpp/icu4x/DateTime.hpp @@ -54,11 +54,11 @@ namespace capi { uint16_t icu4x_DateTime_day_of_year_mv1(const icu4x::capi::DateTime* self); - uint32_t icu4x_DateTime_day_of_month_mv1(const icu4x::capi::DateTime* self); + uint8_t icu4x_DateTime_day_of_month_mv1(const icu4x::capi::DateTime* self); icu4x::capi::IsoWeekday icu4x_DateTime_day_of_week_mv1(const icu4x::capi::DateTime* self); - uint32_t icu4x_DateTime_week_of_month_mv1(const icu4x::capi::DateTime* self, icu4x::capi::IsoWeekday first_weekday); + uint8_t icu4x_DateTime_week_of_month_mv1(const icu4x::capi::DateTime* self, icu4x::capi::IsoWeekday first_weekday); icu4x::capi::WeekOf icu4x_DateTime_week_of_year_mv1(const icu4x::capi::DateTime* self, const icu4x::capi::WeekCalculator* calculator); @@ -173,7 +173,7 @@ inline uint16_t icu4x::DateTime::day_of_year() const { return result; } -inline uint32_t icu4x::DateTime::day_of_month() const { +inline uint8_t icu4x::DateTime::day_of_month() const { auto result = icu4x::capi::icu4x_DateTime_day_of_month_mv1(this->AsFFI()); return result; } @@ -183,7 +183,7 @@ inline icu4x::IsoWeekday icu4x::DateTime::day_of_week() const { return icu4x::IsoWeekday::FromFFI(result); } -inline uint32_t icu4x::DateTime::week_of_month(icu4x::IsoWeekday first_weekday) const { +inline uint8_t icu4x::DateTime::week_of_month(icu4x::IsoWeekday first_weekday) const { auto result = icu4x::capi::icu4x_DateTime_week_of_month_mv1(this->AsFFI(), first_weekday.AsFFI()); return result; diff --git a/ffi/capi/bindings/cpp/icu4x/IsoDate.d.hpp b/ffi/capi/bindings/cpp/icu4x/IsoDate.d.hpp index 5c248a2004..fb48e8a6de 100644 --- a/ffi/capi/bindings/cpp/icu4x/IsoDate.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/IsoDate.d.hpp @@ -47,11 +47,11 @@ class IsoDate { inline uint16_t day_of_year() const; - inline uint32_t day_of_month() const; + inline uint8_t day_of_month() const; inline icu4x::IsoWeekday day_of_week() const; - inline uint32_t week_of_month(icu4x::IsoWeekday first_weekday) const; + inline uint8_t week_of_month(icu4x::IsoWeekday first_weekday) const; inline icu4x::WeekOf week_of_year(const icu4x::WeekCalculator& calculator) const; diff --git a/ffi/capi/bindings/cpp/icu4x/IsoDate.hpp b/ffi/capi/bindings/cpp/icu4x/IsoDate.hpp index 1203469a74..9810abcf60 100644 --- a/ffi/capi/bindings/cpp/icu4x/IsoDate.hpp +++ b/ffi/capi/bindings/cpp/icu4x/IsoDate.hpp @@ -37,11 +37,11 @@ namespace capi { uint16_t icu4x_IsoDate_day_of_year_mv1(const icu4x::capi::IsoDate* self); - uint32_t icu4x_IsoDate_day_of_month_mv1(const icu4x::capi::IsoDate* self); + uint8_t icu4x_IsoDate_day_of_month_mv1(const icu4x::capi::IsoDate* self); icu4x::capi::IsoWeekday icu4x_IsoDate_day_of_week_mv1(const icu4x::capi::IsoDate* self); - uint32_t icu4x_IsoDate_week_of_month_mv1(const icu4x::capi::IsoDate* self, icu4x::capi::IsoWeekday first_weekday); + uint8_t icu4x_IsoDate_week_of_month_mv1(const icu4x::capi::IsoDate* self, icu4x::capi::IsoWeekday first_weekday); icu4x::capi::WeekOf icu4x_IsoDate_week_of_year_mv1(const icu4x::capi::IsoDate* self, const icu4x::capi::WeekCalculator* calculator); @@ -97,7 +97,7 @@ inline uint16_t icu4x::IsoDate::day_of_year() const { return result; } -inline uint32_t icu4x::IsoDate::day_of_month() const { +inline uint8_t icu4x::IsoDate::day_of_month() const { auto result = icu4x::capi::icu4x_IsoDate_day_of_month_mv1(this->AsFFI()); return result; } @@ -107,7 +107,7 @@ inline icu4x::IsoWeekday icu4x::IsoDate::day_of_week() const { return icu4x::IsoWeekday::FromFFI(result); } -inline uint32_t icu4x::IsoDate::week_of_month(icu4x::IsoWeekday first_weekday) const { +inline uint8_t icu4x::IsoDate::week_of_month(icu4x::IsoWeekday first_weekday) const { auto result = icu4x::capi::icu4x_IsoDate_week_of_month_mv1(this->AsFFI(), first_weekday.AsFFI()); return result; diff --git a/ffi/capi/bindings/cpp/icu4x/IsoDateTime.d.hpp b/ffi/capi/bindings/cpp/icu4x/IsoDateTime.d.hpp index a913621458..3158790194 100644 --- a/ffi/capi/bindings/cpp/icu4x/IsoDateTime.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/IsoDateTime.d.hpp @@ -69,11 +69,11 @@ class IsoDateTime { inline uint16_t day_of_year() const; - inline uint32_t day_of_month() const; + inline uint8_t day_of_month() const; inline icu4x::IsoWeekday day_of_week() const; - inline uint32_t week_of_month(icu4x::IsoWeekday first_weekday) const; + inline uint8_t week_of_month(icu4x::IsoWeekday first_weekday) const; inline icu4x::WeekOf week_of_year(const icu4x::WeekCalculator& calculator) const; diff --git a/ffi/capi/bindings/cpp/icu4x/IsoDateTime.hpp b/ffi/capi/bindings/cpp/icu4x/IsoDateTime.hpp index 1dc2f142b5..59da0d02dd 100644 --- a/ffi/capi/bindings/cpp/icu4x/IsoDateTime.hpp +++ b/ffi/capi/bindings/cpp/icu4x/IsoDateTime.hpp @@ -57,11 +57,11 @@ namespace capi { uint16_t icu4x_IsoDateTime_day_of_year_mv1(const icu4x::capi::IsoDateTime* self); - uint32_t icu4x_IsoDateTime_day_of_month_mv1(const icu4x::capi::IsoDateTime* self); + uint8_t icu4x_IsoDateTime_day_of_month_mv1(const icu4x::capi::IsoDateTime* self); icu4x::capi::IsoWeekday icu4x_IsoDateTime_day_of_week_mv1(const icu4x::capi::IsoDateTime* self); - uint32_t icu4x_IsoDateTime_week_of_month_mv1(const icu4x::capi::IsoDateTime* self, icu4x::capi::IsoWeekday first_weekday); + uint8_t icu4x_IsoDateTime_week_of_month_mv1(const icu4x::capi::IsoDateTime* self, icu4x::capi::IsoWeekday first_weekday); icu4x::capi::WeekOf icu4x_IsoDateTime_week_of_year_mv1(const icu4x::capi::IsoDateTime* self, const icu4x::capi::WeekCalculator* calculator); @@ -167,7 +167,7 @@ inline uint16_t icu4x::IsoDateTime::day_of_year() const { return result; } -inline uint32_t icu4x::IsoDateTime::day_of_month() const { +inline uint8_t icu4x::IsoDateTime::day_of_month() const { auto result = icu4x::capi::icu4x_IsoDateTime_day_of_month_mv1(this->AsFFI()); return result; } @@ -177,7 +177,7 @@ inline icu4x::IsoWeekday icu4x::IsoDateTime::day_of_week() const { return icu4x::IsoWeekday::FromFFI(result); } -inline uint32_t icu4x::IsoDateTime::week_of_month(icu4x::IsoWeekday first_weekday) const { +inline uint8_t icu4x::IsoDateTime::week_of_month(icu4x::IsoWeekday first_weekday) const { auto result = icu4x::capi::icu4x_IsoDateTime_week_of_month_mv1(this->AsFFI(), first_weekday.AsFFI()); return result; diff --git a/ffi/capi/bindings/cpp/icu4x/WeekOf.d.hpp b/ffi/capi/bindings/cpp/icu4x/WeekOf.d.hpp index 190ad638ba..704c259c83 100644 --- a/ffi/capi/bindings/cpp/icu4x/WeekOf.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/WeekOf.d.hpp @@ -18,7 +18,7 @@ class WeekRelativeUnit; namespace icu4x { namespace capi { struct WeekOf { - uint16_t week; + uint8_t week; icu4x::capi::WeekRelativeUnit unit; }; @@ -29,7 +29,7 @@ namespace capi { namespace icu4x { struct WeekOf { - uint16_t week; + uint8_t week; icu4x::WeekRelativeUnit unit; inline icu4x::capi::WeekOf AsFFI() const; diff --git a/ffi/capi/bindings/dart/Date.g.dart b/ffi/capi/bindings/dart/Date.g.dart index 1bdbd3dc82..1c12fdf5dd 100644 --- a/ffi/capi/bindings/dart/Date.g.dart +++ b/ffi/capi/bindings/dart/Date.g.dart @@ -269,7 +269,7 @@ external ffi.Pointer _icu4x_Date_to_iso_mv1(ffi.Pointer external int _icu4x_Date_day_of_year_mv1(ffi.Pointer self); @meta.RecordUse() -@ffi.Native)>(isLeaf: true, symbol: 'icu4x_Date_day_of_month_mv1') +@ffi.Native)>(isLeaf: true, symbol: 'icu4x_Date_day_of_month_mv1') // ignore: non_constant_identifier_names external int _icu4x_Date_day_of_month_mv1(ffi.Pointer self); @@ -279,7 +279,7 @@ external int _icu4x_Date_day_of_month_mv1(ffi.Pointer self); external int _icu4x_Date_day_of_week_mv1(ffi.Pointer self); @meta.RecordUse() -@ffi.Native, ffi.Int32)>(isLeaf: true, symbol: 'icu4x_Date_week_of_month_mv1') +@ffi.Native, ffi.Int32)>(isLeaf: true, symbol: 'icu4x_Date_week_of_month_mv1') // ignore: non_constant_identifier_names external int _icu4x_Date_week_of_month_mv1(ffi.Pointer self, int firstWeekday); diff --git a/ffi/capi/bindings/dart/DateTime.g.dart b/ffi/capi/bindings/dart/DateTime.g.dart index 68ccd654f3..aac5ccbbe1 100644 --- a/ffi/capi/bindings/dart/DateTime.g.dart +++ b/ffi/capi/bindings/dart/DateTime.g.dart @@ -360,7 +360,7 @@ external int _icu4x_DateTime_nanosecond_mv1(ffi.Pointer self); external int _icu4x_DateTime_day_of_year_mv1(ffi.Pointer self); @meta.RecordUse() -@ffi.Native)>(isLeaf: true, symbol: 'icu4x_DateTime_day_of_month_mv1') +@ffi.Native)>(isLeaf: true, symbol: 'icu4x_DateTime_day_of_month_mv1') // ignore: non_constant_identifier_names external int _icu4x_DateTime_day_of_month_mv1(ffi.Pointer self); @@ -370,7 +370,7 @@ external int _icu4x_DateTime_day_of_month_mv1(ffi.Pointer self); external int _icu4x_DateTime_day_of_week_mv1(ffi.Pointer self); @meta.RecordUse() -@ffi.Native, ffi.Int32)>(isLeaf: true, symbol: 'icu4x_DateTime_week_of_month_mv1') +@ffi.Native, ffi.Int32)>(isLeaf: true, symbol: 'icu4x_DateTime_week_of_month_mv1') // ignore: non_constant_identifier_names external int _icu4x_DateTime_week_of_month_mv1(ffi.Pointer self, int firstWeekday); diff --git a/ffi/capi/bindings/dart/IsoDate.g.dart b/ffi/capi/bindings/dart/IsoDate.g.dart index b0695f21d1..ce6ebf802e 100644 --- a/ffi/capi/bindings/dart/IsoDate.g.dart +++ b/ffi/capi/bindings/dart/IsoDate.g.dart @@ -205,7 +205,7 @@ external ffi.Pointer _icu4x_IsoDate_to_any_mv1(ffi.Pointer self); @meta.RecordUse() -@ffi.Native)>(isLeaf: true, symbol: 'icu4x_IsoDate_day_of_month_mv1') +@ffi.Native)>(isLeaf: true, symbol: 'icu4x_IsoDate_day_of_month_mv1') // ignore: non_constant_identifier_names external int _icu4x_IsoDate_day_of_month_mv1(ffi.Pointer self); @@ -215,7 +215,7 @@ external int _icu4x_IsoDate_day_of_month_mv1(ffi.Pointer self); external int _icu4x_IsoDate_day_of_week_mv1(ffi.Pointer self); @meta.RecordUse() -@ffi.Native, ffi.Int32)>(isLeaf: true, symbol: 'icu4x_IsoDate_week_of_month_mv1') +@ffi.Native, ffi.Int32)>(isLeaf: true, symbol: 'icu4x_IsoDate_week_of_month_mv1') // ignore: non_constant_identifier_names external int _icu4x_IsoDate_week_of_month_mv1(ffi.Pointer self, int firstWeekday); diff --git a/ffi/capi/bindings/dart/IsoDateTime.g.dart b/ffi/capi/bindings/dart/IsoDateTime.g.dart index a07c815174..837b68bf8a 100644 --- a/ffi/capi/bindings/dart/IsoDateTime.g.dart +++ b/ffi/capi/bindings/dart/IsoDateTime.g.dart @@ -323,7 +323,7 @@ external int _icu4x_IsoDateTime_nanosecond_mv1(ffi.Pointer self); external int _icu4x_IsoDateTime_day_of_year_mv1(ffi.Pointer self); @meta.RecordUse() -@ffi.Native)>(isLeaf: true, symbol: 'icu4x_IsoDateTime_day_of_month_mv1') +@ffi.Native)>(isLeaf: true, symbol: 'icu4x_IsoDateTime_day_of_month_mv1') // ignore: non_constant_identifier_names external int _icu4x_IsoDateTime_day_of_month_mv1(ffi.Pointer self); @@ -333,7 +333,7 @@ external int _icu4x_IsoDateTime_day_of_month_mv1(ffi.Pointer self); external int _icu4x_IsoDateTime_day_of_week_mv1(ffi.Pointer self); @meta.RecordUse() -@ffi.Native, ffi.Int32)>(isLeaf: true, symbol: 'icu4x_IsoDateTime_week_of_month_mv1') +@ffi.Native, ffi.Int32)>(isLeaf: true, symbol: 'icu4x_IsoDateTime_week_of_month_mv1') // ignore: non_constant_identifier_names external int _icu4x_IsoDateTime_week_of_month_mv1(ffi.Pointer self, int firstWeekday); diff --git a/ffi/capi/bindings/dart/WeekOf.g.dart b/ffi/capi/bindings/dart/WeekOf.g.dart index 9174183245..21ff745dae 100644 --- a/ffi/capi/bindings/dart/WeekOf.g.dart +++ b/ffi/capi/bindings/dart/WeekOf.g.dart @@ -3,7 +3,7 @@ part of 'lib.g.dart'; final class _WeekOfFfi extends ffi.Struct { - @ffi.Uint16() + @ffi.Uint8() external int week; @ffi.Int32() external int unit; diff --git a/ffi/capi/bindings/js/WeekOf.mjs b/ffi/capi/bindings/js/WeekOf.mjs index 28aa35f60c..cb6397cdde 100644 --- a/ffi/capi/bindings/js/WeekOf.mjs +++ b/ffi/capi/bindings/js/WeekOf.mjs @@ -38,7 +38,7 @@ export class WeekOf { appendArrayMap, forcePadding ) { - return [this.#week, ...diplomatRuntime.maybePaddingFields(forcePadding, 1 /* x i16 */), this.#unit.ffiValue] + return [this.#week, ...diplomatRuntime.maybePaddingFields(forcePadding, 3 /* x i8 */), this.#unit.ffiValue] } _writeToArrayBuffer( @@ -48,7 +48,7 @@ export class WeekOf { appendArrayMap, forcePadding ) { - diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#week, Uint16Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#week, Uint8Array); diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#unit.ffiValue, Int32Array); } @@ -58,7 +58,7 @@ export class WeekOf { // This method does not attempt to handle any dependencies between lifetimes, the caller // should handle this when constructing edge arrays. #fromFFI(ptr) { - const weekDeref = (new Uint16Array(wasm.memory.buffer, ptr, 1))[0]; + const weekDeref = (new Uint8Array(wasm.memory.buffer, ptr, 1))[0]; this.#week = weekDeref; const unitDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); this.#unit = new WeekRelativeUnit(diplomatRuntime.internalConstructor, unitDeref); diff --git a/ffi/capi/src/date.rs b/ffi/capi/src/date.rs index e2336ab446..ba54b857ca 100644 --- a/ffi/capi/src/date.rs +++ b/ffi/capi/src/date.rs @@ -81,7 +81,7 @@ pub mod ffi { /// Returns the 1-indexed day in the month for this date #[diplomat::rust_link(icu::calendar::Date::day_of_month, FnInStruct)] #[diplomat::attr(auto, getter)] - pub fn day_of_month(&self) -> u32 { + pub fn day_of_month(&self) -> u8 { self.0.day_of_month().0 } @@ -102,7 +102,7 @@ pub mod ffi { FnInStruct, hidden )] - pub fn week_of_month(&self, first_weekday: IsoWeekday) -> u32 { + pub fn week_of_month(&self, first_weekday: IsoWeekday) -> u8 { self.0.week_of_month(first_weekday.into()).0 } @@ -251,7 +251,7 @@ pub mod ffi { /// Returns the 1-indexed day in the month for this date #[diplomat::rust_link(icu::calendar::Date::day_of_month, FnInStruct)] #[diplomat::attr(auto, getter)] - pub fn day_of_month(&self) -> u32 { + pub fn day_of_month(&self) -> u8 { self.0.day_of_month().0 } @@ -272,7 +272,7 @@ pub mod ffi { FnInStruct, hidden )] - pub fn week_of_month(&self, first_weekday: IsoWeekday) -> u32 { + pub fn week_of_month(&self, first_weekday: IsoWeekday) -> u8 { self.0.week_of_month(first_weekday.into()).0 } diff --git a/ffi/capi/src/datetime.rs b/ffi/capi/src/datetime.rs index 306fed9320..cf6dd7e0af 100644 --- a/ffi/capi/src/datetime.rs +++ b/ffi/capi/src/datetime.rs @@ -153,7 +153,7 @@ pub mod ffi { /// Returns the 1-indexed day in the month for this date #[diplomat::rust_link(icu::calendar::Date::day_of_month, FnInStruct)] #[diplomat::attr(auto, getter)] - pub fn day_of_month(&self) -> u32 { + pub fn day_of_month(&self) -> u8 { self.0.date.day_of_month().0 } @@ -174,7 +174,7 @@ pub mod ffi { FnInStruct, hidden )] - pub fn week_of_month(&self, first_weekday: IsoWeekday) -> u32 { + pub fn week_of_month(&self, first_weekday: IsoWeekday) -> u8 { self.0.date.week_of_month(first_weekday.into()).0 } @@ -386,7 +386,7 @@ pub mod ffi { /// Returns the 1-indexed day in the month for this date #[diplomat::rust_link(icu::calendar::Date::day_of_month, FnInStruct)] #[diplomat::attr(auto, getter)] - pub fn day_of_month(&self) -> u32 { + pub fn day_of_month(&self) -> u8 { self.0.date.day_of_month().0 } @@ -407,7 +407,7 @@ pub mod ffi { FnInStruct, hidden )] - pub fn week_of_month(&self, first_weekday: IsoWeekday) -> u32 { + pub fn week_of_month(&self, first_weekday: IsoWeekday) -> u8 { self.0.date.week_of_month(first_weekday.into()).0 } diff --git a/ffi/capi/src/week.rs b/ffi/capi/src/week.rs index 4d643a8bf5..4c7c2e3b02 100644 --- a/ffi/capi/src/week.rs +++ b/ffi/capi/src/week.rs @@ -24,7 +24,7 @@ pub mod ffi { #[diplomat::rust_link(icu::calendar::week::WeekOf, Struct)] #[diplomat::out] pub struct WeekOf { - pub week: u16, + pub week: u8, pub unit: WeekRelativeUnit, } /// A Week calculator, useful to be passed in to `week_of_year()` on Date and DateTime types