diff --git a/components/calendar/src/chinese.rs b/components/calendar/src/chinese.rs index d89bbf3cda3..dfc561ee6c2 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 diff --git a/components/calendar/src/dangi.rs b/components/calendar/src/dangi.rs index e59488d4198..ada73761393 100644 --- a/components/calendar/src/dangi.rs +++ b/components/calendar/src/dangi.rs @@ -265,7 +265,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 { diff --git a/components/calendar/src/types.rs b/components/calendar/src/types.rs index ec87545f5ac..7e18d35c932 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 1128d3a6321..1536e906a9d 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/src/date.rs b/ffi/capi/src/date.rs index e2336ab4468..ba54b857caf 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 306fed93202..cf6dd7e0af6 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 4d643a8bf53..4c7c2e3b023 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