diff --git a/src/month.rs b/src/month.rs index 146a98ebe..9e14dad6d 100644 --- a/src/month.rs +++ b/src/month.rs @@ -227,6 +227,12 @@ impl Months { pub const fn new(num: u32) -> Self { Self(num) } + + /// Returns the total number of months in the `Months` instance. + #[inline] + pub const fn as_u32(&self) -> u32 { + self.0 + } } /// An error resulting from reading `` value with `FromStr`. @@ -298,7 +304,7 @@ mod month_serde { #[cfg(test)] mod tests { use super::Month; - use crate::{Datelike, OutOfRange, TimeZone, Utc}; + use crate::{Datelike, Months, OutOfRange, TimeZone, Utc}; #[test] fn test_month_enum_try_from() { @@ -353,6 +359,13 @@ mod tests { assert!(Month::September > Month::March); } + #[test] + 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] #[cfg(feature = "serde")] fn test_serde_serialize() {