#duration #time #date-time #time-parser #diff #parser

relativetime

🦀 Rust 库,用于打印可读的相对时间差

4 个版本

0.1.4 2022年5月17日
0.1.3 2022年5月17日
0.1.1 2022年5月17日
0.1.0 2022年5月17日

#444日期和时间

31 每月下载量
用于 render-cli

MIT 许可证

9KB
130

GitHub Contributors Stars Build Status Downloads Crates.io docs.rs

relativetime

relativetimestd::time::Durationchrono::Duration 提供了 trait,以便轻松显示可读的相对时间。

use relativetime::{RelativeTime, NegativeRelativeTime};


fn main() {
    let d = std::time::Duration::from_secs(1);
    assert_eq!(d.relative_time(), "in a few seconds");
    assert_eq!(d.relative_time_in_past(), "a few seconds ago");
    
    let d = chrono::Duration::from_secs(-1);
    assert_eq!(d.relative_time(), "a few seconds ago");
    let d = chrono::Duration::from_secs(1);
    assert_eq!(d.relative_time(), "in a few seconds");
}

请参阅 docs 了解 API,以及 测试 了解更多示例用法。

贡献

欢迎贡献!

依赖

~39–320KB