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
use crate::*;
use NthWeekday::*;
holiday_const!(
MLKJ_DAY, "Martin Luther King Jr. Day", Third, Weekday::Mon, January
);
holiday_const!(
GROUNDHOG_DAY, "Groundhog Day", February, 2
);
holiday_const!(
SUPERBOWL_SUNDAY, "Super Bowl Sunday", First, Weekday::Sun, February
);
holiday_const!(
PRESIDENTS_DAY, "President's Day", Third, Weekday::Mon, February
);
holiday_const!(
VALENTINES_DAY, "Valentine's Day", February, 14
);
holiday_const!(
DST_START, "Daylight Saving Time Starts", Second, Weekday::Sun, March
);
holiday_const!(
APRIL_FOOLS_DAY, "April Fool's Day", April, 1
);
holiday_const!(
KENTUCKY_DERBY, "Kentucky Derby", First, Weekday::Sat, May
);
holiday_const!(
MEMORIAL_DAY, "Memorial Day", Last, Weekday::Mon, May
);
holiday_const!(
MOTHERS_DAY, "Mother's Day", Second, Weekday::Sun, May
);
holiday_const!(
FLAG_DAY, "Flag Day", June, 14
);
holiday_const!(
INDEPENDENCE_DAY, "Independence Day", July, 4
);
holiday_const!(
FATHERS_DAY, "Father's Day", Third, Weekday::Sun, June
);
holiday_const!(
LABOR_DAY, "Labor Day", First, Weekday::Mon, September
);
holiday_const!(
HALLOWEEN, "Halloween", October, 31
);
holiday_const!(
COLUMBUS_DAY, "Columbus Day", Second, Weekday::Mon, October
);
holiday_const!(
VETERANS_DAY, "Veteran's Day", November, 11
);
holiday_const!(
DST_END, "Daylight Saving Time Ends", First, Weekday::Sun, November
);
holiday_const!(
THANKSGIVING, "Thanksgiving", Fourth, Weekday::Thu, November
);
#[test]
fn holiday_eq() {
assert_eq!(THANKSGIVING, NthWeekdayOfMonth::new(4, Weekday::Thu, 11));
assert_eq!(THANKSGIVING, NaiveDate::from_ymd(2020, 11, 26));
assert_eq!(THANKSGIVING, NaiveDate::from_ymd(2021, 11, 25));
assert_eq!(HALLOWEEN, NaiveDate::from_ymd(2020, 10, 31));
assert_eq!(HALLOWEEN, NaiveDate::from_ymd(2021, 10, 31));
}
#[test]
fn holiday_ord() {
let mut vec = vec![
super::global::NEW_YEARS_EVE,
THANKSGIVING,
super::global::NEW_YEARS_DAY,
HALLOWEEN,
super::global::CHRISTMAS,
];
vec.sort();
dbg!(&vec);
let exp = vec![
super::global::NEW_YEARS_DAY,
HALLOWEEN,
THANKSGIVING,
super::global::CHRISTMAS,
super::global::NEW_YEARS_EVE,
];
assert_eq!(vec, exp);
}