#![no_std]
#[inline]
pub const fn is_leap_year(year: i32) -> bool {
(year % 4 == 0 && year % 100 != 0) || year % 400 == 0
}
#[inline]
pub const fn get_days_in_month(year: i32, month: u8) -> Option<u8> {
match month {
1 | 3 | 5 | 7 | 8 | 10 | 12 => Some(31),
4 | 6 | 9 | 11 => Some(30),
2 => {
if is_leap_year(year) {
Some(29)
} else {
Some(28)
}
}
_ => None,
}
}
#[inline]
pub const fn get_days_in_month_2(leap_year: bool, month: u8) -> Option<u8> {
match month {
1 | 3 | 5 | 7 | 8 | 10 | 12 => Some(31),
4 | 6 | 9 | 11 => Some(30),
2 => {
if leap_year {
Some(29)
} else {
Some(28)
}
}
_ => None,
}
}
#[inline]
pub const fn get_days_in_year(year: i32) -> u16 {
if is_leap_year(year) {
366
} else {
365
}
}
#[inline]
pub const fn get_days_in_year_2(leap_year: bool) -> u16 {
if leap_year {
366
} else {
365
}
}