5个版本 (1个稳定版)
1.0.0 | 2022年7月11日 |
---|---|
0.3.1 | 2020年10月23日 |
0.3.0 | 2020年10月21日 |
0.2.2 | 2020年10月1日 |
0.1.0 | 2020年9月19日 |
#126 in 国际化 (i18n)
每月61次下载
35KB
788 行
瑞典节假日
一个简单的软件包,用于跟踪瑞典每年的节假日。
获取指定年份的节假日日期
use holidays_se::Holiday;
assert_eq!(Holiday::Paskdagen.in_year(2020), Stockholm.ymd(2020, 4, 12));
更有用的案例可能是根据日期类型将给定时间段分割成多个片段
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"
);
依赖项
~1.8–3MB
~52K SLoC