Skip to content

Commit

Permalink
Add Months::as_u32() (#1373)
Browse files Browse the repository at this point in the history
  • Loading branch information
danwilliams committed Jan 9, 2024
1 parent 6033afe commit 5536687
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<Month>` value with `FromStr`.
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 5536687

Please sign in to comment.