5 releases (1 stable)
1.0.0 | Jul 11, 2022 |
---|---|
0.3.1 | Oct 23, 2020 |
0.3.0 | Oct 21, 2020 |
0.2.2 | Oct 1, 2020 |
0.1.0 | Sep 19, 2020 |
#156 in Internationalization (i18n)
31 downloads per month
35KB
788 lines
Holidays Sweden
A simple crate to keep track of holidays each year in sweden.
Getting the date of a Holiday in a given year:
use holidays_se::Holiday;
assert_eq!(Holiday::Paskdagen.in_year(2020), Stockholm.ymd(2020, 4, 12));
A more useful case might be to partition a given time range into slices depending on the kind of day:
use chrono::TimeZone;
use chrono_tz::Europe::Stockholm;
let start = Stockholm.ymd(2020, 9, 18).and_hms(0, 0, 0); // Friday
let end = Stockholm.ymd(2020, 9, 21).and_hms(13, 15, 0); // Monday at 13:15
let mut iter = holidays_se::slice_on_day_kind(start..end);
assert_eq!(
Some(DayKindSlice {
range: start.naive_local()
..Stockholm.ymd(2020, 9, 19).and_hms(0, 0, 0).naive_local(),
kind: DayKind::Weekday,
}),
iter.next(),
"First slice should be the whole of Friday"
);
assert_eq!(
Some(DayKindSlice {
range: Stockholm.ymd(2020, 9, 19).and_hms(0, 0, 0).naive_local()
..Stockholm.ymd(2020, 9, 20).and_hms(0, 0, 0).naive_local(),
kind: DayKind::DayBeforeHoliday,
}),
iter.next(),
"Second slice should be the whole of Saturday"
);
assert_eq!(
Some(DayKindSlice {
range: Stockholm.ymd(2020, 9, 20).and_hms(0, 0, 0).naive_local()
..Stockholm.ymd(2020, 9, 21).and_hms(0, 0, 0).naive_local(),
kind: DayKind::Holiday,
}),
iter.next(),
"Third slice should be the whole of Sunday"
);
assert_eq!(
Some(DayKindSlice {
range: Stockholm.ymd(2020, 9, 21).and_hms(0, 0, 0).naive_local()
..Stockholm.ymd(2020, 9, 21).and_hms(13, 15, 0).naive_local(),
kind: DayKind::Weekday,
}),
iter.next(),
"Fourth slice should be Monday until 13:15"
);
assert!(
iter.next().is_none(),
"Iterator should be empty after monday"
);
Dependencies
~1.8–3MB
~50K SLoC