2 个不稳定版本

0.2.1 2024年8月19日
0.1.1 2024年8月11日

182日期和时间

Download history 101/week @ 2024-08-11

每月 101 次下载

GPL-3.0 或更新版

14KB
266 行(不包括注释)

intervalle

这个小实用程序 crate 实现了 --since 参数的格式,这是 systemdjournalctl

-S, --since=, -U, --until=
   Start showing entries on or newer than the specified date, or on or
   older than the specified date, respectively. Date specifications
   should be of the format "2012-10-30 18:17:16". If the time part is
   omitted, "00:00:00" is assumed. If only the seconds component is
   omitted, ":00" is assumed. If the date component is omitted, the
   current day is assumed. Alternatively the strings "yesterday",
   "today", "tomorrow" are understood, which refer to 00:00:00 of the
   day before the current day, the current day, or the day after the
   current day, respectively.  "now" refers to the current time.
   Finally, relative times may be specified, prefixed with "-" or "+",
   referring to times before or after the current time, respectively.

用法

该 crate 定义了一个 TimeSpec 枚举,表示时间参数。您可以使用 TimeSpec::parse 函数解析字符串,并让程序确定 'now' 的时间点(如 todaytomorrowyesterday 所需)或使用 TimeSpec::parse_with_anchor 方法提供自己的 time::PrimitiveDateTime 用于计算。

use since::TimeSpec;

fn main() {
    let timespec = std::env::args().skip(1).next().unwrap();

    match TimeSpec::parse(&timespec) {
        Ok(t) => println!("{t:?}"),
        Err(e) => eprintln!("{e}"),
    }
}

依赖项

~2MB
~32K SLoC