1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// RustQuant: A Rust library for quantitative finance tools.
// Copyright (C) 2022-2024 https://github.com/avhz
// Dual licensed under Apache 2.0 and MIT.
// See:
// - LICENSE-APACHE.md
// - LICENSE-MIT.md
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//! This module defines Australian holidays and calendars.
use crate::calendar::Calendar;
use crate::utilities::unpack_date;
use time::{Date, Month, Weekday};
use RustQuant_iso::*;
/// Australian national holiday calendar.
#[derive(Debug, Clone, Copy)]
pub struct AustraliaCalendar;
impl AustraliaCalendar {
/// Creates a new instance of the Australian calendar.
pub fn new() -> Self {
Self
}
}
impl Calendar for AustraliaCalendar {
fn new() -> Self {
Self
}
fn name(&self) -> &'static str {
"Australia"
}
fn country_code(&self) -> ISO_3166 {
AUSTRALIA
}
fn market_identifier_code(&self) -> ISO_10383 {
XASX
}
fn is_holiday(&self, date: Date) -> bool {
let (y, m, d, wd, yd, em) = unpack_date(date, false);
if
// New Year's Day (possibly moved to Monday)
((d == 1 || ((d == 2 || d == 3) && wd == Weekday::Monday)) && m == Month::January)
// Australia Day, January 26th (possibly moved to Monday)
|| ((d == 26 || ((d == 27 || d == 28) && wd == Weekday::Monday)) && m == Month::January)
// Good Friday
|| (yd == em - 3)
// Easter Monday
|| (yd == em)
// ANZAC Day
|| (d == 25 && m == Month::April)
// Queen's Birthday, second Monday in June
|| ((d > 7 && d <= 14) && wd == Weekday::Monday && m == Month::June)
// Bank Holiday, first Monday in August
|| (d <= 7 && wd == Weekday::Monday && m == Month::August)
// Labour Day, first Monday in October
|| (d <= 7 && wd == Weekday::Monday && m == Month::October)
// Christmas, December 25th (possibly moved to Monday or Tuesday)
|| ((d == 25 || (d == 27 && (wd == Weekday::Monday || wd == Weekday::Tuesday))) && m == Month::December)
// Boxing Day, December 26th (possibly moved to Monday or Tuesday)
|| ((d == 26 || (d == 28 && (wd == Weekday::Monday || wd == Weekday::Tuesday))) && m == Month::December)
// National Day of Mourning for Her Majesty, September 22 (only 2022)
|| (d == 22 && m == Month::September && y == 2022)
{
return true;
}
false
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// UNIT TESTS
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#[cfg(test)]
mod test_australia {
use super::*;
use time::macros::date;
// Test to verify the name() method.
#[test]
fn test_name() {
let calendar = AustraliaCalendar;
assert_eq!(calendar.name(), "Australia");
}
// Test to verify if weekends are not considered business days.
#[test]
fn test_is_weekend() {
let calendar = AustraliaCalendar;
let sat = date!(2023 - 08 - 26);
let sun = date!(2023 - 08 - 27);
assert!(!calendar.is_business_day(sat));
assert!(!calendar.is_business_day(sun));
}
// Test to verify if the is_business_day() method properly accounts for public holidays.
#[test]
fn test_is_public_holiday() {
let calendar = AustraliaCalendar;
let new_years_day = date!(2023 - 01 - 01);
let australia_day = date!(2023 - 01 - 26);
let anzac_day = date!(2023 - 04 - 25);
let christmas = date!(2023 - 12 - 25);
assert!(!calendar.is_business_day(new_years_day));
assert!(!calendar.is_business_day(australia_day));
assert!(!calendar.is_business_day(anzac_day));
assert!(!calendar.is_business_day(christmas));
}
// Test to verify if the is_business_day() method properly accounts for regular business days.
#[test]
fn test_is_regular_business_day() {
let calendar = AustraliaCalendar;
let regular_day1 = date!(2023 - 03 - 01);
let regular_day2 = date!(2023 - 07 - 12);
let regular_day3 = date!(2023 - 11 - 17);
assert!(calendar.is_business_day(regular_day1));
assert!(calendar.is_business_day(regular_day2));
assert!(calendar.is_business_day(regular_day3));
}
}