use crate::{Calendar, Date, EasterOffset, FixedDate, Month, OneOff, Rule, Weekend, Year};
pub const TARGET: Calendar<'static> = Calendar {
name: "TARGET",
weekend: Weekend::SAT_SUN,
rules: &[
Rule::Fixed(FixedDate::new(Month::Jan, 1)),
Rule::Easter(EasterOffset::good_friday().from_year(Year::literal(2000))),
Rule::Easter(EasterOffset::easter_monday().from_year(Year::literal(2000))),
Rule::Fixed(FixedDate::new(Month::May, 1).from_year(Year::literal(2000))),
Rule::Fixed(FixedDate::new(Month::Dec, 25)),
Rule::Fixed(FixedDate::new(Month::Dec, 26).from_year(Year::literal(2000))),
Rule::OneOff(OneOff::new(Date::literal(1998, Month::Dec, 31))),
Rule::OneOff(OneOff::new(Date::literal(1999, Month::Dec, 31))),
Rule::OneOff(OneOff::new(Date::literal(2001, Month::Dec, 31))),
],
};
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod tests {
use super::*;
fn ymd(y: u16, m: Month, d: u8) -> Date {
Date::from_ymd(y, m, d).unwrap()
}
fn holidays(year: u16) -> alloc::vec::Vec<Date> {
let jan1 = ymd(year, Month::Jan, 1);
let range = jan1..ymd(year, Month::Dec, 31).add_days(1).unwrap();
TARGET
.holidays(range)
.filter(|d| !TARGET.is_weekend(*d))
.collect()
}
#[test]
fn published_closings_2024() {
assert_eq!(
holidays(2024),
[
ymd(2024, Month::Jan, 1), ymd(2024, Month::Mar, 29), ymd(2024, Month::Apr, 1), ymd(2024, Month::May, 1), ymd(2024, Month::Dec, 25), ymd(2024, Month::Dec, 26), ],
);
}
#[test]
fn published_closings_2026() {
assert_eq!(
holidays(2026),
[
ymd(2026, Month::Jan, 1), ymd(2026, Month::Apr, 3), ymd(2026, Month::Apr, 6), ymd(2026, Month::May, 1), ymd(2026, Month::Dec, 25), ],
);
}
#[test]
fn easter_labour_and_goodwill_start_in_2000() {
for d in [
ymd(1999, Month::Apr, 2),
ymd(1999, Month::Apr, 5),
ymd(1999, Month::May, 1),
ymd(1999, Month::Dec, 26),
] {
assert!(!TARGET.is_holiday(d), "{d} should not be a TARGET holiday");
}
assert!(TARGET.is_holiday(ymd(1999, Month::Jan, 1)));
assert!(TARGET.is_holiday(ymd(1999, Month::Dec, 25)));
}
#[test]
fn year_end_closings_are_three_years_only() {
assert!(TARGET.is_holiday(ymd(1998, Month::Dec, 31)));
assert!(TARGET.is_holiday(ymd(1999, Month::Dec, 31)));
assert!(TARGET.is_holiday(ymd(2001, Month::Dec, 31)));
assert!(!TARGET.is_holiday(ymd(2000, Month::Dec, 31)));
assert!(!TARGET.is_holiday(ymd(2024, Month::Dec, 31)));
}
#[test]
fn weekend_holidays_are_lost_not_shifted() {
assert!(!TARGET.is_holiday(ymd(2022, Month::Jan, 3)));
assert!(TARGET.is_business_day(ymd(2022, Month::Jan, 3)));
}
}