use std::{fs::File, path::PathBuf, time::Duration}; use chrono::{DateTime, Local, Datelike, Weekday}; use holiday::{ holidays::{united_states::*, global::*}, BeforeAfterDate, }; fn main() { let path = PathBuf::from(std::env::var("OUT_DIR").unwrap()); let file = path.join("touch.txt"); std::thread::sleep(Duration::from_millis(10)); println!("cargo:rerun-if-changed={}", path.display()); let last_compile = match File::open(&file) { Ok(file) => Some(DateTime::::from(file.metadata().unwrap().modified().unwrap())), Err(_) => None, }; let time = Local::now(); if last_compile .map(|last_compile| if cfg!(feature = "slow_down") { time.signed_duration_since(last_compile).num_seconds() < 10 } else { false }) .unwrap_or(false) { too_fast() } else { std::fs::write(&file, "touch").unwrap(); } let holidays = [ CHRISTMAS, CHRISTMAS_EVE, LEAP_DAY, NEW_YEARS_DAY, NEW_YEARS_EVE, ST_PATRICKS_DAY, APRIL_FOOLS_DAY, COLUMBUS_DAY, FATHERS_DAY, FLAG_DAY, GROUNDHOG_DAY, HALLOWEEN, INDEPENDENCE_DAY, LABOR_DAY, MEMORIAL_DAY, MLKJ_DAY, MOTHERS_DAY, PRESIDENTS_DAY, SUPERBOWL_SUNDAY, THANKSGIVING, VALENTINES_DAY, VETERANS_DAY, ]; for holiday in holidays { if time.date_naive() == holiday.after(&time.date_naive()) { its_a_day(holiday.name()) } } match time.date_naive().weekday() { Weekday::Sat => its_a_day("Saturday"), Weekday::Sun => its_a_day("Sunday"), _ => {} } } fn its_a_day(name: &str) { panic!( "\n\n=== Its {}! ===\n\nnote: rustc can't compile stuff today.\n\n", name ); } fn too_fast() { panic!("\n\n=== Slow Down! ===\n\nnote: You are compiling to much. Take a break.\n\n"); }