Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<Month>` value with `FromStr`.
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down