Skip to content

Commit b01c0bc

Browse files
committed
feat: add switzerland calendar
1 parent 1f9e8a2 commit b01c0bc

File tree

3 files changed

+159
-0
lines changed

3 files changed

+159
-0
lines changed

crates/RustQuant_time/src/calendar.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ pub enum Market {
8585
UnitedKingdom,
8686
/// United States national calendar.
8787
UnitedStates,
88+
/// Switzerland national calendar.
89+
Switzerland,
8890
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8991
// MARKETS / EXCHANGES
9092
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -432,6 +434,7 @@ impl Calendar {
432434
Market::Singapore => is_holiday_impl_singapore(date),
433435
Market::UnitedKingdom => is_holiday_impl_united_kingdom(date),
434436
Market::UnitedStates => is_holiday_impl_united_states(date),
437+
Market::Switzerland => is_holiday_impl_switzerland(date),
435438
// Special case markets:
436439
Market::None => false,
437440
Market::Weekends => false,

crates/RustQuant_time/src/countries/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,7 @@ pub(crate) use united_kingdom::*;
112112
/// United States holidays and calendars.
113113
pub mod united_states;
114114
pub(crate) use united_states::*;
115+
116+
/// Switzerland holidays and calendars.
117+
pub mod switzerland;
118+
pub(crate) use switzerland::*;
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
use crate::utilities::unpack_date;
2+
use time::{Date, Month};
3+
4+
pub(crate) fn is_holiday_impl_switzerland(date: Date) -> bool {
5+
let (_, m, d, _, yd, em) = unpack_date(date, false);
6+
7+
is_new_year(m, d)
8+
|| is_berchtholdstag(m, d)
9+
|| is_good_friday(yd, em)
10+
|| is_easter_monday(yd, em)
11+
|| is_labour_day(m, d)
12+
|| is_ascension_day(yd, em)
13+
|| is_whit_monday(yd, em)
14+
|| is_national_holiday(m, d)
15+
|| is_christmas_eve(m, d)
16+
|| is_christmas_day(m, d)
17+
|| is_st_stephens_day(m, d)
18+
|| is_new_year_eve(m, d)
19+
}
20+
21+
#[inline]
22+
fn is_new_year(month: Month, day: u8) -> bool {
23+
month == Month::January && day == 1
24+
}
25+
26+
#[inline]
27+
fn is_berchtholdstag(month: Month, day: u8) -> bool {
28+
month == Month::January && day == 2
29+
}
30+
31+
#[inline]
32+
fn is_good_friday(yd: u16, em: u16) -> bool {
33+
yd == em - 3
34+
}
35+
36+
#[inline]
37+
fn is_easter_monday(yd: u16, em: u16) -> bool {
38+
yd == em
39+
}
40+
41+
#[inline]
42+
fn is_labour_day(month: Month, day: u8) -> bool {
43+
month == Month::May && day == 1
44+
}
45+
46+
#[inline]
47+
fn is_ascension_day(yd: u16, em: u16) -> bool {
48+
yd == em + 38
49+
}
50+
51+
#[inline]
52+
fn is_whit_monday(yd: u16, em: u16) -> bool {
53+
yd == em + 49
54+
}
55+
56+
#[inline]
57+
fn is_national_holiday(month: Month, day: u8) -> bool {
58+
month == Month::August && day == 1
59+
}
60+
61+
#[inline]
62+
fn is_christmas_eve(month: Month, day: u8) -> bool {
63+
month == Month::December && day == 24
64+
}
65+
66+
#[inline]
67+
fn is_christmas_day(month: Month, day: u8) -> bool {
68+
month == Month::December && day == 25
69+
}
70+
71+
#[inline]
72+
fn is_st_stephens_day(month: Month, day: u8) -> bool {
73+
month == Month::December && day == 26
74+
}
75+
76+
#[inline]
77+
fn is_new_year_eve(month: Month, day: u8) -> bool {
78+
month == Month::December && day == 31
79+
}
80+
81+
#[cfg(test)]
82+
mod tests_switzerland {
83+
use crate::{Calendar, Market};
84+
85+
const CALENDAR: Calendar = Calendar::new(Market::Switzerland);
86+
87+
#[test]
88+
fn new_years_day_2025() {
89+
let date = time::macros::date!(2025 - 01 - 01);
90+
assert!(!CALENDAR.is_business_day(date));
91+
}
92+
93+
#[test]
94+
fn whit_monday_2025() {
95+
let date = time::macros::date!(2025 - 06 - 09);
96+
assert!(!CALENDAR.is_business_day(date));
97+
}
98+
99+
#[test]
100+
fn regular_day_2025() {
101+
let date = time::macros::date!(2025 - 03 - 17);
102+
assert!(CALENDAR.is_business_day(date));
103+
}
104+
105+
#[test]
106+
fn national_holiday_2025() {
107+
let date = time::macros::date!(2025 - 08 - 01);
108+
assert!(!CALENDAR.is_business_day(date));
109+
}
110+
111+
#[test]
112+
fn good_friday_2025() {
113+
let date = time::macros::date!(2025 - 04 - 18);
114+
assert!(!CALENDAR.is_business_day(date));
115+
}
116+
117+
#[test]
118+
fn berchtholdstag_2025() {
119+
let date = time::macros::date!(2025 - 01 - 02);
120+
assert!(!CALENDAR.is_business_day(date));
121+
}
122+
123+
#[test]
124+
fn ascension_2025() {
125+
let date = time::macros::date!(2025 - 05 - 29);
126+
assert!(!CALENDAR.is_business_day(date));
127+
}
128+
129+
#[test]
130+
fn christmas_2025() {
131+
let date = time::macros::date!(2025 - 12 - 25);
132+
assert!(!CALENDAR.is_business_day(date));
133+
}
134+
135+
#[test]
136+
fn st_stephens_day_2025() {
137+
let date = time::macros::date!(2025 - 12 - 26);
138+
assert!(!CALENDAR.is_business_day(date));
139+
}
140+
141+
#[test]
142+
fn new_years_eve_2025() {
143+
let date = time::macros::date!(2025 - 12 - 31);
144+
assert!(!CALENDAR.is_business_day(date));
145+
}
146+
147+
#[test]
148+
fn christmas_eve_2025() {
149+
let date = time::macros::date!(2025 - 12 - 24);
150+
assert!(!CALENDAR.is_business_day(date));
151+
}
152+
}

0 commit comments

Comments
 (0)