use crate::{format::try_parse_fmt_string, internals};
#[cfg(not(feature = "std"))]
use alloc::string::String;
use const_fn::const_fn;
pub fn validate_format_string(s: impl AsRef<str>) -> Result<(), String> {
try_parse_fmt_string(s.as_ref()).map(|_| ())
}
const DAYS_IN_MONTH_COMMON_LEAP: [[u16; 12]; 2] = [
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
];
pub(crate) const fn days_in_year_month(year: i32, month: u8) -> u8 {
DAYS_IN_MONTH_COMMON_LEAP[is_leap_year(year) as usize][month as usize - 1] as u8
}
pub const fn is_leap_year(year: i32) -> bool {
(year % 4 == 0) & ((year % 100 != 0) | (year % 400 == 0))
}
pub const fn days_in_year(year: i32) -> u16 {
365 + is_leap_year(year) as u16
}
#[const_fn("1.46")]
pub const fn weeks_in_year(year: i32) -> u8 {
let weekday = internals::Date::from_yo_unchecked(year, 1).iso_weekday_number();
if weekday == 4 || weekday == 3 && is_leap_year(year) {
53
} else {
52
}
}