Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/template/day.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Day {
pub fn today() -> Option<Self> {
let offset = FixedOffset::east_opt(SERVER_UTC_OFFSET * 3600)?;
let today = Utc::now().with_timezone(&offset);
if today.month() == day_count!() as u32 && today.day() <= day_count!() as u32 {
if today.month() == 12 && today.day() <= day_count!() as u32 {
Self::new(u8::try_from(today.day()).ok()?)
} else {
None
Expand Down Expand Up @@ -99,18 +99,18 @@ impl Error for DayFromStrError {}

impl Display for DayFromStrError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("expecting a day number between 1 and 12")
f.write_str(&format!("expecting a day number between 1 and {}", day_count!()))
}
}

/* -------------------------------------------------------------------------- */

/// An iterator that yields every day of advent from the 1st to the 12th.
/// An iterator that yields every day of advent from the 1st to the 12th (or 25th before 2025).
pub fn all_days() -> AllDays {
AllDays::new()
}

/// An iterator that yields every day of advent from the 1st to the 12th.
/// An iterator that yields every day of advent from the 1st to the 12th (or 25th before 2025).
pub struct AllDays {
current: u8,
}
Expand All @@ -129,7 +129,7 @@ impl Iterator for AllDays {
if self.current > day_count!() {
return None;
}
// NOTE: the iterator starts at 1 and we have verified that the value is not above 12.
// NOTE: the iterator starts at 1, and we have verified that the value is not above 12 (or 25).
let day = Day(self.current);
self.current += 1;

Expand All @@ -145,7 +145,7 @@ macro_rules! day {
($day:expr) => {
const {
$crate::template::Day::new($day)
.expect("invalid day number, expecting a value between 1 and 12")
.expect("invalid day number, expecting a value between 1 and 12 (or 25 before 2025)")
}
};
}
Expand Down