use crate::shared::shared;
use crate::time::calendar::{Calendar, CalendarImpl, is_weekend_sat_sun, orthodox_easter_monday};
use crate::time::date::{Date, Month};
use crate::time::weekday::Weekday;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Market {
Use,
}
pub struct Ukraine;
impl Ukraine {
pub fn new(market: Market) -> Calendar {
let imp: crate::shared::Shared<dyn CalendarImpl> = match market {
Market::Use => shared(UseImpl),
};
Calendar::from_impl(imp)
}
}
struct UseImpl;
impl CalendarImpl for UseImpl {
fn name(&self) -> String {
"Ukrainian stock exchange".to_string()
}
fn is_weekend(&self, w: Weekday) -> bool {
is_weekend_sat_sun(w)
}
fn is_business_day(&self, date: Date) -> bool {
let w = date.weekday();
let d = date.day_of_month();
let dd = date.day_of_year();
let m = date.month();
let y = date.year();
let em = orthodox_easter_monday(y);
!(is_weekend_sat_sun(w)
|| ((d == 1 || ((d == 2 || d == 3) && w == Weekday::Monday))
&& m == Month::January)
|| ((d == 7 || ((d == 8 || d == 9) && w == Weekday::Monday))
&& m == Month::January)
|| ((d == 8 || ((d == 9 || d == 10) && w == Weekday::Monday))
&& m == Month::March)
|| (dd == em)
|| (dd == em + 49)
|| ((d == 1 || d == 2 || (d == 3 && w == Weekday::Monday)) && m == Month::May)
|| ((d == 9 || ((d == 10 || d == 11) && w == Weekday::Monday)) && m == Month::May)
|| (d == 28 && m == Month::June)
|| (d == 24 && m == Month::August)
|| (d == 14 && m == Month::October && y >= 2015))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn name_matches_quantlib() {
assert_eq!(Ukraine::new(Market::Use).name(), "Ukrainian stock exchange");
}
#[test]
fn fixed_holidays() {
let c = Ukraine::new(Market::Use);
for (d, m) in [
(28, Month::June), (24, Month::August), ] {
assert!(c.is_holiday(Date::new(d, m, 2019)), "{d} {m} 2019");
}
}
#[test]
fn weekend_rule() {
let c = Ukraine::new(Market::Use);
assert!(c.is_weekend(Weekday::Saturday));
assert!(c.is_weekend(Weekday::Sunday));
assert!(!c.is_weekend(Weekday::Friday));
}
}