From e0c4ec5498c0645f8850e275cf247889ae1dd12e Mon Sep 17 00:00:00 2001 From: Gokul Date: Mon, 10 Apr 2023 19:50:25 +0400 Subject: [PATCH] Atuin stats with day, month, week and year filter (#858) * atuin stats with day, month and year * fixed stats for week * review suggestions * rust formatted --- src/command/client/stats.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/command/client/stats.rs b/src/command/client/stats.rs index d730df4..5134f22 100644 --- a/src/command/client/stats.rs +++ b/src/command/client/stats.rs @@ -82,6 +82,22 @@ impl Cmd { }; let history = if words.as_str() == "all" { db.list(FilterMode::Global, &context, None, false).await? + } else if words.trim() == "today" { + let start = Local::now().date().and_hms(0, 0, 0); + let end = start + Duration::days(1); + db.range(start.into(), end.into()).await? + } else if words.trim() == "month" { + let end = Local::now().date().and_hms(0, 0, 0); + let start = end - Duration::days(31); + db.range(start.into(), end.into()).await? + } else if words.trim() == "week" { + let end = Local::now().date().and_hms(0, 0, 0); + let start = end - Duration::days(7); + db.range(start.into(), end.into()).await? + } else if words.trim() == "year" { + let end = Local::now().date().and_hms(0, 0, 0); + let start = end - Duration::days(365); + db.range(start.into(), end.into()).await? } else { let start = parse_date_string(&words, Local::now(), settings.dialect.into())?; let end = start + Duration::days(1);