Skip to content

Commit

Permalink
Renamed Months::num_months() to as_u32(), and removed num_years()
Browse files Browse the repository at this point in the history
  • Loading branch information
danwilliams committed Jan 9, 2024
1 parent 9d44606 commit b56e3a4
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,9 @@ impl Months {

/// Returns the total number of months in the `Months` instance.
#[inline]
pub const fn num_months(&self) -> u32 {
pub const fn as_u32(&self) -> u32 {
self.0
}

/// Returns the total number of whole years in the `Months` instance.
#[inline]
pub const fn num_years(&self) -> u32 {
self.0 / 12
}
}

/// An error resulting from reading `<Month>` value with `FromStr`.
Expand Down Expand Up @@ -366,21 +360,10 @@ mod tests {
}

#[test]
fn test_months_num_months() {
assert_eq!(Months::new(0).num_months(), 0);
assert_eq!(Months::new(1).num_months(), 1);
assert_eq!(Months::new(u32::MAX).num_months(), u32::MAX);
}

#[test]
fn test_months_num_years() {
assert_eq!(Months::new(0).num_years(), 0);
assert_eq!(Months::new(1).num_years(), 0);
assert_eq!(Months::new(11).num_years(), 0);
assert_eq!(Months::new(12).num_years(), 1);
assert_eq!(Months::new(23).num_years(), 1);
assert_eq!(Months::new(24).num_years(), 2);
assert_eq!(Months::new(u32::MAX).num_years(), u32::MAX / 12);
fn test_months_as_u32() {
assert_eq!(Months::new(0).as_u32(), 0);
assert_eq!(Months::new(1).as_u32(), 1);
assert_eq!(Months::new(u32::MAX).as_u32(), u32::MAX);
}

#[test]
Expand Down

0 comments on commit b56e3a4

Please sign in to comment.