#日期-时间 #日期 #时间 #年度 #纪念日

holiday

一个用于定义和迭代年度重复日期和假日的 Rust 库

3 个版本

0.1.2 2022年11月26日
0.1.1 2021年1月22日
0.1.0 2021年1月22日

#243日期和时间

Download history · Rust 包仓库 55/week @ 2024-04-07 · Rust 包仓库 8/week @ 2024-04-14 · Rust 包仓库 4/week @ 2024-04-21 · Rust 包仓库 1/week @ 2024-04-28 · Rust 包仓库 34/week @ 2024-05-05 · Rust 包仓库 41/week @ 2024-05-12 · Rust 包仓库 17/week @ 2024-05-19 · Rust 包仓库 14/week @ 2024-06-02 · Rust 包仓库 152/week @ 2024-06-09 · Rust 包仓库 34/week @ 2024-06-16 · Rust 包仓库 15/week @ 2024-06-23 · Rust 包仓库 11/week @ 2024-06-30 · Rust 包仓库 78/week @ 2024-07-07 · Rust 包仓库 34/week @ 2024-07-21 · Rust 包仓库

123 每月下载量
rustc-holidays 中使用

MIT 许可协议

36KB
868

holiday

一个用于定义和迭代年度重复日期和假日的 Rust 库。

创建一个新的假日

Holiday 可以是一个固定日期,如 '4月2日',或者是一个月中的第 n 个工作日,如 '4月第一个星期五'。

use holiday::*;
use chrono::{Weekday, NaiveDate};

// Regular `fixed` holiday
let holiday = Holiday::new_fixed("April 2nd", April, 2);
assert_eq!(holiday.in_year(2021), NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(holiday, NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(holiday, NaiveDate::from_ymd(2022, 4, 2));

// Pastover: First Friday in April, an `nth` holiday
let pastover = Holiday::new_nth("Pastover", First, Weekday::Fri, April);
assert_eq!(pastover.in_year(2021), NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(pastover, NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(pastover, NaiveDate::from_ymd(2022, 4, 1));

迭代假日的出现。

HolidayIter 类型是一个迭代器,用于迭代假日的出现。


lib.rs:

holiday

一个用于定义年度重复日期和假日的库

创建一个新的假日

Holiday 可以是一个固定日期,如 '4月2日',或者是一个月中的第 n 个工作日,如 '4月第一个星期五'。

use holiday::*;
use chrono::{Weekday, NaiveDate};

// Regular `fixed` holiday
let holiday = Holiday::new_fixed("April 2nd", April, 2);
assert_eq!(holiday.in_year(2021), NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(holiday, NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(holiday, NaiveDate::from_ymd(2022, 4, 2));

// Pastover: First Friday in April, an `nth` holiday
let pastover = Holiday::new_nth("Pastover", First, Weekday::Fri, April);
assert_eq!(pastover.in_year(2021), NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(pastover, NaiveDate::from_ymd(2021, 4, 2));
assert_eq!(pastover, NaiveDate::from_ymd(2022, 4, 1));

依赖关系

~1MB
~18K SLoC