#![cfg(feature = "holiday")]
#![allow(clippy::unwrap_used, clippy::expect_used)]
use jiff::civil::date;
use timeglyph::{holiday, RenderZone};
#[test]
fn known_fixed_holiday() {
assert_eq!(
holiday::lookup("US", date(2020, 7, 4)),
Some("Independence Day".to_string())
);
assert_eq!(
holiday::lookup("US", date(2020, 12, 25)),
Some("Christmas Day".to_string())
);
}
#[test]
fn ordinary_day_is_none() {
assert_eq!(holiday::lookup("US", date(2020, 3, 16)), None);
assert_eq!(holiday::lookup("US", date(2020, 7, 5)), None);
}
#[test]
fn lunar_holiday_native_locale() {
let cny = holiday::lookup("CN", date(2020, 1, 25)).expect("CN 2020-01-25 is a holiday");
assert!(cny.contains('\u{6625}'), "expected 春节, got {cny:?}"); }
#[test]
fn unknown_country_is_none() {
assert_eq!(holiday::lookup("ZZ", date(2020, 1, 1)), None);
}
#[test]
fn case_insensitive_country() {
assert_eq!(
holiday::lookup("us", date(2020, 7, 4)),
Some("Independence Day".to_string())
);
}
#[test]
fn zone_maps_to_country() {
assert_eq!(holiday::country_for_zone("Asia/Shanghai"), Some("CN"));
assert_eq!(holiday::country_for_zone("America/New_York"), Some("US"));
assert_eq!(holiday::country_for_zone("Europe/London"), Some("GB"));
assert_eq!(holiday::country_for_zone("Etc/UTC"), None);
assert_eq!(holiday::country_for_zone("Nowhere/Nope"), None);
}
#[test]
fn holiday_in_named_zone() {
let sh = RenderZone::Named(jiff::tz::TimeZone::get("Asia/Shanghai").unwrap());
let cny = holiday::in_zone(&sh, date(2020, 1, 25)).expect("CNY in Asia/Shanghai");
assert!(cny.contains('\u{6625}'), "expected 春节, got {cny:?}");
assert_eq!(holiday::in_zone(&RenderZone::Utc, date(2020, 1, 25)), None);
}
#[test]
fn holiday_from_rendered_string() {
let sh = RenderZone::Named(jiff::tz::TimeZone::get("Asia/Shanghai").unwrap());
let cny = holiday::in_zone_rendered(&sh, "2020-01-25T08:00:00+08:00").unwrap();
assert!(cny.contains('\u{6625}'));
assert_eq!(holiday::in_zone_rendered(&sh, "not-a-date"), None);
}
#[test]
fn alias_zone_resolves_to_country() {
assert_eq!(holiday::country_for_zone("Asia/Chongqing"), Some("CN"));
assert_eq!(holiday::country_for_zone("Asia/Harbin"), Some("CN"));
assert_eq!(holiday::country_for_zone("US/Eastern"), Some("US"));
}
#[test]
fn dataset_loaded() {
assert!(
holiday::supported_country_count() > 200,
"holiday dataset looks empty/truncated: {} countries",
holiday::supported_country_count()
);
}