1#[cfg(feature = "with-chrono")]
2mod chrono;
3mod iter;
4mod num;
5#[cfg(feature = "with-num-traits")]
6mod num_traits;
7#[cfg(feature = "with-serde")]
8mod serde;
9mod str;
10
11#[cfg(feature = "with-chrono")]
12pub use self::chrono::CHRONO_MONTHS;
13#[cfg(feature = "with-serde")]
14pub use self::serde::{serde_str, serde_u64};
15pub use iter::MonthIterator;
16
17#[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Debug, Copy, Clone)]
18#[repr(u8)]
19pub enum Month {
20 Jan = 1,
21 Feb = 2,
22 Mar = 3,
23 Apr = 4,
24 May = 5,
25 Jun = 6,
26 Jul = 7,
27 Aug = 8,
28 Sep = 9,
29 Oct = 10,
30 Nov = 11,
31 Dec = 12,
32}
33
34pub static MONTHS: &[Month] = &[
35 Month::Jan,
36 Month::Feb,
37 Month::Mar,
38 Month::Apr,
39 Month::May,
40 Month::Jun,
41 Month::Jul,
42 Month::Aug,
43 Month::Sep,
44 Month::Oct,
45 Month::Nov,
46 Month::Dec,
47];
48pub(crate) const MONTH_N_MIN: u8 = 1;
49pub(crate) const MONTH_N_MAX: u8 = 12;
50
51impl Month {
52 pub fn first() -> Self {
53 MONTHS[(MONTH_N_MIN - 1) as usize].to_owned()
54 }
55 pub fn last() -> Self {
56 MONTHS[(MONTH_N_MAX - 1) as usize].to_owned()
57 }
58
59 pub fn next(&self) -> Option<Self> {
60 if self == &Self::last() {
61 None
62 } else {
63 Some(MONTHS[(self.to_owned() as u8 + 1 - 1) as usize].to_owned())
64 }
65 }
66 pub fn prev(&self) -> Option<Self> {
67 if self == &Self::first() {
68 None
69 } else {
70 Some(MONTHS[(self.to_owned() as u8 - 1 - 1) as usize].to_owned())
71 }
72 }
73}