Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spoutn1k/intervalle
Parse a time definition like systemd
https://github.com/spoutn1k/intervalle
Last synced: 9 days ago
JSON representation
Parse a time definition like systemd
- Host: GitHub
- URL: https://github.com/spoutn1k/intervalle
- Owner: spoutn1k
- Created: 2024-08-09T16:15:38.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2024-08-19T12:07:05.000Z (4 months ago)
- Last Synced: 2024-11-27T20:13:07.444Z (25 days ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `intervalle`
This small utility crate implements the format for the `--since` argument of `systemd`'s `journalctl`:
```
-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.
```## Usage
The crate defines a `TimeSpec` enum that represents the time argument. You can parse a string with the `TimeSpec::parse` function and let the program determine the point in time for 'now' (as the values `today`, `tomorrow` and `yesterday` need) or use the `TimeSpec::parse_with_anchor` method to supply your own `time::PrimitiveDateTime` to use for calculations.
```rs
use since::TimeSpec;fn main() {
let timespec = std::env::args().skip(1).next().unwrap();match TimeSpec::parse(×pec) {
Ok(t) => println!("{t:?}"),
Err(e) => eprintln!("{e}"),
}
}
```