use chrono::{Datelike, FixedOffset, Utc};
#[derive(Debug, Clone, Copy)]
pub(crate) struct CalendarDate {
pub year: usize,
pub month: u32,
pub day: usize,
}
impl CalendarDate {
pub(crate) fn today() -> Self {
let offset = FixedOffset::west_opt(5 * 3600).expect("UTC-5 is a valid offset");
let now = Utc::now().with_timezone(&offset);
Self {
year: usize::try_from(now.year()).expect("Expected a positive calendar year"),
month: now.month(),
day: now.day() as usize,
}
}
pub(crate) fn unlocked_days(&self, year: usize) -> usize {
if year > self.year || year < 2015 {
return 0;
}
let total = edition_days(year);
if year < self.year {
return total;
}
if self.month != 12 {
return 0;
}
self.day.min(total)
}
}
pub(crate) const fn edition_days(year: usize) -> usize {
match year {
2015..=2024 => 25,
2025.. => 12,
_ => 0,
}
}