2 个版本
0.1.1 | 2020年3月31日 |
---|---|
0.1.0 | 2020年3月30日 |
#371 in 日期和时间
16KB
172 代码行
chrono crate 的非官方扩展。
概述
此 crate 的目的是为 chrono crate 提供各种辅助/扩展。
为什么?
决定编写此 crate 的第一个需求是拥有“自定义”的周定义。例如,在法国,电影于周三上映。
功能
使用自定义周定义计算周数。
法国剧院日历有一个周定义,第一周至少有4天,从周三开始。例如
- 2019年的第一周从2019-01-02开始。
- 2016年的第一周从2015-12-30开始。
自定义周定义的 API 受 Java API Java WeekFields 的启发。周由以下定义
- 第一天-of-week(周一,周二,……)。
- 第一周的最小天数。
示例
use chrono::NaiveDate;
use chrono_ext::{WeekSpecification, CustomWeek};
fn use_french_theater_week() {
let french_theater_week: WeekSpecification = WeekSpecification::french_theater_week();
let date = NaiveDate::from_ymd(2017, 1, 3);
let week = french_theater_week.week(date);
println!("{}", week.format("%Y - W%W")); // 2016 - W53
}
安装
将以下内容添加到 Cargo.toml
中的 [dependencies]
chrono_ext = "0.1.1"
依赖项
~1MB
~19K SLoC