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
use chrono::{Datelike, NaiveDate};
mod holidays;
mod regions;
pub use holidays::GermanHoliday;
pub use regions::GermanRegion;
pub trait DateExt {
fn is_public_holiday_in(&self, region: GermanRegion) -> bool;
fn public_holiday_in(&self, region: GermanRegion) -> Option<GermanHoliday>;
fn is_holiday(&self, holiday: GermanHoliday) -> bool;
}
impl DateExt for NaiveDate {
fn is_public_holiday_in(&self, region: GermanRegion) -> bool {
region.is_holiday(*self)
}
fn public_holiday_in(&self, region: GermanRegion) -> Option<GermanHoliday> {
region.holiday_from_date(*self)
}
fn is_holiday(&self, holiday: GermanHoliday) -> bool {
let holiday_date = holiday.date(self.year());
Some(*self) == holiday_date
}
}