use derive_more::Display;
use crate::macros::impl_traits;
use crate::day::Day;
#[repr(u8)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[derive(Copy,Clone,Debug,Default,PartialEq,PartialOrd,Eq,Ord,Hash)]
#[derive(Display)]
pub enum DaysInMonth {
#[default]
ThirtyOne = 31,
Thirty = 30,
TwentyNine = 29,
TwentyEight = 28,
}
impl_traits!{ DaysInMonth => u8 |
u8,u16,u32,u64,u128,usize |
i8,i16,i32,i64,i128,isize
}
impl DaysInMonth {
#[inline]
pub const fn inner(self) -> u8 {
unsafe { std::mem::transmute(self) }
}
#[inline]
pub const fn new(day: u8) -> Self {
assert!(day > 27, "day must not be < 28");
assert!(day < 32, "day must not be > 31");
unsafe { Self::new_unchecked(day) }
}
#[inline]
pub const unsafe fn new_unchecked(day: u8) -> Self {
debug_assert!(day > 27, "day must not be < 28");
debug_assert!(day < 32, "day must not be > 31");
std::mem::transmute(day)
}
#[inline]
pub const fn as_str(self) -> &'static str {
match self {
Self::ThirtyOne => "ThirtyOne",
Self::Thirty => "Thirty",
Self::TwentyNine => "TwentyNine",
Self::TwentyEight => "TwentyEight",
}
}
#[inline]
pub const fn as_str_num(self) -> &'static str {
match self {
Self::ThirtyOne => "31",
Self::Thirty => "30",
Self::TwentyNine => "29",
Self::TwentyEight => "28",
}
}
#[inline]
pub const fn as_str_lower(self) -> &'static str {
match self {
Self::ThirtyOne => "thirtyfirst",
Self::Thirty => "thirtieth",
Self::TwentyNine => "twentyninth",
Self::TwentyEight => "twentyeighth",
}
}
#[inline]
pub const fn as_str_upper(self) -> &'static str {
match self {
Self::ThirtyOne => "THIRTYFIRST",
Self::Thirty => "THIRTIETH",
Self::TwentyNine => "TWENTYNINTH",
Self::TwentyEight => "TWENTYEIGHTH",
}
}
#[inline]
pub const fn as_day(self) -> Day {
unsafe { std::mem::transmute(self) }
}
}