From 8b9aae7076f39a1ebeecb3e2b823503f437812fa Mon Sep 17 00:00:00 2001 From: Benjamin Vergnaud <9599845+bvergnaud@users.noreply.github.com> Date: Fri, 21 Oct 2022 21:21:14 +0200 Subject: [PATCH] docs: add more details about date parsing in the stats command (#579) * docs: add more details about date parsing in the stats command * chore: Replace chrono-english crate with interim --- Cargo.lock | 59 +++++++++++++++++++++++++----------- Cargo.toml | 2 +- atuin-client/Cargo.toml | 2 +- atuin-client/src/settings.rs | 9 +++--- docs/stats.md | 22 +++++++++++--- src/command/client/search.rs | 14 +++------ src/command/client/stats.rs | 2 +- 7 files changed, 71 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 339b156..636a0ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,7 +87,6 @@ dependencies = [ "atuin-server", "base64", "chrono", - "chrono-english", "clap", "clap_complete", "cli-table", @@ -96,6 +95,7 @@ dependencies = [ "eyre", "fs-err", "indicatif", + "interim", "itertools", "log", "pretty_env_logger", @@ -119,12 +119,12 @@ dependencies = [ "atuin-common", "base64", "chrono", - "chrono-english", "config", "directories", "eyre", "fs-err", "hex", + "interim", "itertools", "lazy_static", "log", @@ -243,6 +243,12 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" + [[package]] name = "bitflags" version = "1.3.2" @@ -310,16 +316,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "chrono-english" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73d909da7eb4a7d88c679c3f5a1bc09d965754e0adb2e7627426cef96a00d6f" -dependencies = [ - "chrono", - "scanlex", -] - [[package]] name = "chronoutil" version = "0.2.3" @@ -944,6 +940,16 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "interim" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ffd2ac8397b9574daa4ffa7ede4427dd249cadaa900719d4b01154a5631d38b" +dependencies = [ + "chrono", + "logos", +] + [[package]] name = "ipnet" version = "2.5.0" @@ -1028,6 +1034,29 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "logos" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1" +dependencies = [ + "logos-derive", +] + +[[package]] +name = "logos-derive" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c" +dependencies = [ + "beef", + "fnv", + "proc-macro2", + "quote", + "regex-syntax", + "syn", +] + [[package]] name = "matchers" version = "0.1.0" @@ -1613,12 +1642,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scanlex" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "088c5d71572124929ea7549a8ce98e1a6fd33d0a38367b09027b382e67c033db" - [[package]] name = "schannel" version = "0.1.20" diff --git a/Cargo.toml b/Cargo.toml index 50dd568..ddeff7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ unicode-width = "0.1" itertools = "0.10.5" tokio = { version = "1", features = ["full"] } async-trait = "0.1.58" -chrono-english = "0.1.4" +interim = { version = "0.1.0", features = ["chrono"] } cli-table = { version = "0.4", default-features = false } base64 = "0.13.0" crossbeam-channel = "0.5.1" diff --git a/atuin-client/Cargo.toml b/atuin-client/Cargo.toml index d22210c..44ebc48 100644 --- a/atuin-client/Cargo.toml +++ b/atuin-client/Cargo.toml @@ -31,7 +31,7 @@ eyre = "0.6" directories = "4" uuid = { version = "1.2", features = ["v4"] } whoami = "1.1.2" -chrono-english = "0.1.4" +interim = { version = "0.1.0", features = ["chrono"] } config = { version = "0.13", default-features = false, features = ["toml"] } serde = { version = "1.0.145", features = ["derive"] } serde_json = "1.0.86" diff --git a/atuin-client/src/settings.rs b/atuin-client/src/settings.rs index b743a15..ec7d9fe 100644 --- a/atuin-client/src/settings.rs +++ b/atuin-client/src/settings.rs @@ -55,6 +55,7 @@ impl FilterMode { } // FIXME: Can use upstream Dialect enum if https://github.com/stevedonovan/chrono-english/pull/16 is merged +// FIXME: Above PR was merged, but dependency was changed to interim (fork of chrono-english) in the ... interim #[derive(Clone, Debug, Deserialize, Copy)] pub enum Dialect { #[serde(rename = "us")] @@ -64,11 +65,11 @@ pub enum Dialect { Uk, } -impl From for chrono_english::Dialect { - fn from(d: Dialect) -> chrono_english::Dialect { +impl From for interim::Dialect { + fn from(d: Dialect) -> interim::Dialect { match d { - Dialect::Uk => chrono_english::Dialect::Uk, - Dialect::Us => chrono_english::Dialect::Us, + Dialect::Uk => interim::Dialect::Uk, + Dialect::Us => interim::Dialect::Us, } } } diff --git a/docs/stats.md b/docs/stats.md index 9c08ce1..b683416 100644 --- a/docs/stats.md +++ b/docs/stats.md @@ -1,10 +1,18 @@ # `atuin stats` Atuin can also calculate stats based on your history - this is currently a -little basic, but more features to come +little basic, but more features to come. + +## 1-day stats + +You provide the starting point, and Atuin computes the stats for 24h from that point. +Date parsing is provided by `interim`, which supports different formats +for full or relative dates. Certain formats rely on the dialect option in your +[configuration](config.md#dialect) to differentiate day from month. +Refer to [the module's documentation](https://docs.rs/interim/0.1.0/interim/#supported-formats) for more details on the supported date formats. ``` -$ atuin stats day last friday +$ atuin stats last friday +---------------------+------------+ | Statistic | Value | @@ -16,12 +24,18 @@ $ atuin stats day last friday | Unique commands ran | 213 | +---------------------+------------+ -$ atuin stats day 01/01/21 # also accepts absolute dates +# A few more examples: +$ atuin stats 2018-04-01 +$ atuin stats April 1 +$ atuin stats 01/04/22 +$ atuin stats last thursday 3pm # between last thursday 3:00pm and the following friday 3:00pm ``` -It can also calculate statistics for all of known history: +## Full history stats ``` +$ atuin stats +# or $ atuin stats all +---------------------+-------+ diff --git a/src/command/client/search.rs b/src/command/client/search.rs index 26026f3..da91577 100644 --- a/src/command/client/search.rs +++ b/src/command/client/search.rs @@ -154,11 +154,8 @@ async fn run_non_interactive( } if let Some(before) = &before { - let before = chrono_english::parse_date_string( - before.as_str(), - Utc::now(), - chrono_english::Dialect::Uk, - ); + let before = + interim::parse_date_string(before.as_str(), Utc::now(), interim::Dialect::Uk); if before.is_err() || h.timestamp.gt(&before.unwrap()) { return false; @@ -166,11 +163,8 @@ async fn run_non_interactive( } if let Some(after) = &after { - let after = chrono_english::parse_date_string( - after.as_str(), - Utc::now(), - chrono_english::Dialect::Uk, - ); + let after = + interim::parse_date_string(after.as_str(), Utc::now(), interim::Dialect::Uk); if after.is_err() || h.timestamp.lt(&after.unwrap()) { return false; diff --git a/src/command/client/stats.rs b/src/command/client/stats.rs index a00eb36..f0c774a 100644 --- a/src/command/client/stats.rs +++ b/src/command/client/stats.rs @@ -1,10 +1,10 @@ use std::collections::HashMap; use chrono::{prelude::*, Duration}; -use chrono_english::parse_date_string; use clap::Parser; use cli_table::{format::Justify, print_stdout, Cell, Style, Table}; use eyre::{bail, Result}; +use interim::parse_date_string; use atuin_client::{ database::{current_context, Database},