use crate::calendar::days_from_civil;
const NOON_JDN_AT_EPOCH: i64 = 2_440_588;
pub(crate) fn day_pillar_offset(year: i32, month: u8, day: u8) -> i64 {
days_from_civil(year, month, day) as i64 + NOON_JDN_AT_EPOCH - 11
}
#[cfg(test)]
mod tests {
use super::*;
fn cycle(year: i32, month: u8, day: u8) -> (i64, i64) {
let offset = day_pillar_offset(year, month, day);
(offset.rem_euclid(10), offset.rem_euclid(12))
}
#[test]
fn known_day_pillars_match_reference() {
assert_eq!(cycle(1970, 1, 1), (7, 5));
assert_eq!(cycle(2000, 1, 1), (4, 6));
assert_eq!(cycle(1984, 2, 2), (2, 2));
assert_eq!(cycle(1850, 1, 1), (8, 0));
assert_eq!(cycle(2150, 12, 31), (5, 5));
}
#[test]
fn noon_jdn_matches_reference_floor() {
assert_eq!(day_pillar_offset(1970, 1, 1) + 11, 2_440_588);
assert_eq!(day_pillar_offset(2000, 1, 1) + 11, 2_451_545);
assert_eq!(day_pillar_offset(1850, 1, 1) + 11, 2_396_759);
assert_eq!(day_pillar_offset(2150, 12, 31) + 11, 2_506_696);
}
}