From 5536687c0d4dfae66130cc44c04e08d9f2797708 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 9 Jan 2024 12:24:41 +0000 Subject: [PATCH] Add Months::as_u32() (#1373) --- src/month.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/month.rs b/src/month.rs index 2f18f9a10b..1e1531d716 100644 --- a/src/month.rs +++ b/src/month.rs @@ -233,6 +233,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`. @@ -302,7 +308,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() { @@ -357,6 +363,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() {