use crate::utilities::is_weekend;
use time::Date;
use RustQuant_iso::*;
pub trait Calendar {
fn new() -> Self;
fn name(&self) -> &'static str;
fn is_holiday(&self, date: Date) -> bool;
fn country_code(&self) -> ISO_3166;
fn market_identifier_code(&self) -> ISO_10383;
fn is_business_day(&self, date: Date) -> bool {
!is_weekend(date) && !self.is_holiday(date)
}
fn all_holidays_between(&self, start_date: Date, end_date: Date) -> Vec<Date> {
let mut holidays = Vec::with_capacity((end_date - start_date).whole_days() as usize);
let mut temp_date = start_date;
while temp_date <= end_date {
if self.is_holiday(temp_date) {
holidays.push(temp_date);
}
temp_date = temp_date.next_day().unwrap();
}
holidays.sort();
holidays
}
fn all_business_days_between(&self, start_date: Date, end_date: Date) -> Vec<Date> {
let mut business_days = Vec::with_capacity((end_date - start_date).whole_days() as usize);
let mut temp_date = start_date;
while temp_date <= end_date {
if self.is_business_day(temp_date) {
business_days.push(temp_date);
}
temp_date = temp_date.next_day().unwrap();
}
business_days.sort();
business_days
}
}