Skip to content

Commit 5536687

Browse files
authored
Add Months::as_u32() (#1373)
1 parent 6033afe commit 5536687

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/month.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ impl Months {
233233
pub const fn new(num: u32) -> Self {
234234
Self(num)
235235
}
236+
237+
/// Returns the total number of months in the `Months` instance.
238+
#[inline]
239+
pub const fn as_u32(&self) -> u32 {
240+
self.0
241+
}
236242
}
237243

238244
/// An error resulting from reading `<Month>` value with `FromStr`.
@@ -302,7 +308,7 @@ mod month_serde {
302308
#[cfg(test)]
303309
mod tests {
304310
use super::Month;
305-
use crate::{Datelike, OutOfRange, TimeZone, Utc};
311+
use crate::{Datelike, Months, OutOfRange, TimeZone, Utc};
306312

307313
#[test]
308314
fn test_month_enum_try_from() {
@@ -357,6 +363,13 @@ mod tests {
357363
assert!(Month::September > Month::March);
358364
}
359365

366+
#[test]
367+
fn test_months_as_u32() {
368+
assert_eq!(Months::new(0).as_u32(), 0);
369+
assert_eq!(Months::new(1).as_u32(), 1);
370+
assert_eq!(Months::new(u32::MAX).as_u32(), u32::MAX);
371+
}
372+
360373
#[test]
361374
#[cfg(feature = "serde")]
362375
fn test_serde_serialize() {

0 commit comments

Comments
 (0)