From d46f5e010e8800280b5f0dc3b4b115256028fcbd Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Tue, 15 Jul 2025 17:12:56 -0600 Subject: [PATCH 1/2] WIP: teach `ent list` to filter based on done-time This commit is WIP because times are serialized to RFC 3339, which uses ":" to separate hours, minutes, and seconds, and this conflicts with the current Filter String which uses ":" to separate "filter chunks". Something's got to give. --- src/bin/ent/main.rs | 13 +++++++++++++ src/lib.rs | 31 +++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/bin/ent/main.rs b/src/bin/ent/main.rs index 5c794e5..af01182 100644 --- a/src/bin/ent/main.rs +++ b/src/bin/ent/main.rs @@ -129,6 +129,19 @@ fn handle_command( } } + if let Some(issue_done_time) = issue.done_time { + if let Some(start_done_time) = filter.start_done_time { + if start_done_time > issue_done_time { + continue; + } + } + if let Some(end_done_time) = filter.end_done_time { + if end_done_time < issue_done_time { + continue; + } + } + } + // This issue passed all the filters, include it in list. uuids_by_state .entry(issue.state.clone()) diff --git a/src/lib.rs b/src/lib.rs index 17104ea..fcface4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,10 @@ use std::str::FromStr; pub mod comment; +pub mod database; pub mod git; pub mod issue; pub mod issues; -pub mod database; #[derive(Debug, thiserror::Error)] pub enum ParseFilterError { @@ -12,6 +12,8 @@ pub enum ParseFilterError { ParseError, #[error(transparent)] IssueParseError(#[from] crate::issue::IssueError), + #[error(transparent)] + ChronoParseError(#[from] chrono::format::ParseError), } // FIXME: It's easy to imagine a full dsl for filtering issues, for now @@ -23,6 +25,8 @@ pub struct Filter<'a> { pub include_assignees: std::collections::HashSet<&'a str>, pub include_tags: std::collections::HashSet<&'a str>, pub exclude_tags: std::collections::HashSet<&'a str>, + pub start_done_time: Option>, + pub end_done_time: Option>, } impl<'a> Filter<'a> { @@ -38,9 +42,11 @@ impl<'a> Filter<'a> { include_assignees: std::collections::HashSet::<&'a str>::new(), include_tags: std::collections::HashSet::<&'a str>::new(), exclude_tags: std::collections::HashSet::<&'a str>::new(), + start_done_time: None, + end_done_time: None, }; - for filter_chunk_str in filter_str.split(":") { + for filter_chunk_str in filter_str.split(" ") { let tokens: Vec<&str> = filter_chunk_str.split("=").collect(); if tokens.len() != 2 { return Err(ParseFilterError::ParseError); @@ -76,6 +82,27 @@ impl<'a> Filter<'a> { } } + "done-time" => { + println!("done-time arg: {}", tokens[1]); + let times: Vec<&str> = tokens[1].split("..").collect(); + if times.len() > 2 { + return Err(ParseFilterError::ParseError); + } + println!(" {:?}", times); + if times[0].len() != 0 { + f.start_done_time = Some( + chrono::DateTime::parse_from_rfc3339(times[0])? + .with_timezone(&chrono::Local), + ); + } + if times[1].len() != 0 { + f.end_done_time = Some( + chrono::DateTime::parse_from_rfc3339(times[1])? + .with_timezone(&chrono::Local), + ); + } + } + _ => { println!("unknown filter chunk '{}'", filter_chunk_str); return Err(ParseFilterError::ParseError); From 61232b70fc47295b758bef482377c2599a7a54be Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Tue, 15 Jul 2025 17:14:33 -0600 Subject: [PATCH 2/2] filter cleanup --- src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fcface4..3ec1ba8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,12 +83,10 @@ impl<'a> Filter<'a> { } "done-time" => { - println!("done-time arg: {}", tokens[1]); let times: Vec<&str> = tokens[1].split("..").collect(); if times.len() > 2 { return Err(ParseFilterError::ParseError); } - println!(" {:?}", times); if times[0].len() != 0 { f.start_done_time = Some( chrono::DateTime::parse_from_rfc3339(times[0])?