use core::num::NonZero;
pub(crate) use time_core::util::{days_in_month_leap, range_validated};
pub use time_core::util::{days_in_year, is_leap_year, weeks_in_year};
use crate::Month;
#[derive(Debug, Clone, Copy)]
pub(crate) enum Overflow {
Positive,
Negative,
}
pub(crate) enum DateAdjustment {
Previous,
Next,
None,
}
#[inline]
pub const fn days_in_month(month: Month, year: i32) -> u8 {
time_core::util::days_in_month(month as u8, year)
}
#[deprecated(
since = "0.3.37",
note = "use `days_in_month` or `Month::length` instead"
)]
#[inline]
pub const fn days_in_year_month(year: i32, month: Month) -> u8 {
days_in_month(month, year)
}
#[inline]
pub(crate) const fn leap_ordinal_to_month_day(leap: bool, ordinal: u16) -> (Month, u8) {
let ordinal = ordinal as u32;
let jan_feb_len = 59 + leap as u32;
let (month_adj, ordinal_adj) = if ordinal <= jan_feb_len {
(0, 0)
} else {
(2, jan_feb_len)
};
let ordinal = ordinal - ordinal_adj;
let month = (ordinal * 268 + 8031) >> 13;
let days_in_preceding_months = (month * 3917 - 3866) >> 7;
let day = ordinal - days_in_preceding_months;
let month = month + month_adj;
(
unsafe {
match Month::from_number(NonZero::new_unchecked(month as u8)) {
Ok(month) => month,
Err(_) => core::hint::unreachable_unchecked(),
}
},
day as u8,
)
}
#[cfg(feature = "local-offset")]
#[inline]
pub unsafe fn refresh_tz_unchecked() {
unsafe { crate::sys::refresh_tz_unchecked() };
}
#[cfg(feature = "local-offset")]
#[inline]
pub fn refresh_tz() -> Option<()> {
crate::sys::refresh_tz()
}
#[doc(hidden)]
#[cfg(feature = "local-offset")]
#[expect(
clippy::missing_const_for_fn,
reason = "no longer used; original implementation was not const"
)]
#[deprecated(since = "0.3.37", note = "no longer needed; TZ is refreshed manually")]
pub mod local_offset {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Soundness {
Sound,
Unsound,
}
#[inline]
pub unsafe fn set_soundness(_: Soundness) {}
#[inline]
pub fn get_soundness() -> Soundness {
Soundness::Sound
}
}