#duration #date-time #friendly #utility #chrono

aion

一个友好的Rust持续时间与日期时间实用工具包

3个不稳定版本

0.2.0 2020年1月21日
0.1.1 2020年1月20日
0.1.0 2020年1月19日

388日期和时间 中排名

Download history 142/week @ 2024-03-08 51/week @ 2024-03-15 20/week @ 2024-03-22 21/week @ 2024-03-29 7/week @ 2024-04-05 7/week @ 2024-04-12 5/week @ 2024-04-19 67/week @ 2024-05-24 16/week @ 2024-05-31 25/week @ 2024-06-07 6/week @ 2024-06-14

每月下载量 51

MIT 许可证

6KB
99

Aion

Aion是一个实用工具包,受Rails启发,允许你以友好的方式编写DurationDateTime

// Easily represent a chrono::Duration
let two_days = 2.days();
let attention_span = 1.seconds();

// Add or subtract durations from the current time (UTC)
let now = Utc::now();
let three_hours_from_now = now + 3.hours();
let two_hours_from_now = 2.hours().from_now();
let last_week = 7.days().ago(); // or 1.weeks().ago()

// More complex DateTimes can be represented using before() and after() methods
let christmas = Utc.ymd(2020, 12, 25).and_hms(0, 0, 0);
let two_weeks_before_christmas = 2.weeks().before(christmas);
let boxing_day = 1.days().after(christmas);

安装

将以下内容添加到你的Cargo.toml文件中

[dependencies]
aion = "0.2"

示例

示例位于example文件夹中。你可以通过以下方式运行它

cargo run --example example

限制

目前此工具包仅会返回DateTime<Utc>

致谢

此工具包使用了chrono。感谢这个出色的工具包。

依赖

~1MB
~18K SLoC