use crate::shared::shared;
use crate::time::calendar::{Calendar, CalendarImpl, is_weekend_sat_sun};
use crate::time::date::Date;
use crate::time::weekday::Weekday;
pub struct WeekendsOnly;
impl WeekendsOnly {
pub fn new() -> Calendar {
Calendar::from_impl(shared(Impl))
}
}
struct Impl;
impl CalendarImpl for Impl {
fn name(&self) -> String {
"weekends only".to_string()
}
fn is_weekend(&self, w: Weekday) -> bool {
is_weekend_sat_sun(w)
}
fn is_business_day(&self, date: Date) -> bool {
!is_weekend_sat_sun(date.weekday())
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::time::date::Month;
#[test]
fn only_weekends_are_holidays() {
let c = WeekendsOnly::new();
assert!(c.is_business_day(Date::new(1, Month::January, 2018))); assert!(c.is_business_day(Date::new(25, Month::December, 2018))); assert!(c.is_holiday(Date::new(6, Month::January, 2018))); assert!(c.is_holiday(Date::new(7, Month::January, 2018))); }
#[test]
fn name_matches_quantlib() {
assert_eq!(WeekendsOnly::new().name(), "weekends only");
}
}