Compare commits

...

2 commits

Author SHA1 Message Date
61232b70fc filter cleanup 2025-07-15 17:14:33 -06:00
d46f5e010e 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.
2025-07-15 17:12:56 -06:00
2 changed files with 40 additions and 2 deletions

View file

@ -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())

View file

@ -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<chrono::DateTime<chrono::Local>>,
pub end_done_time: Option<chrono::DateTime<chrono::Local>>,
}
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,25 @@ impl<'a> Filter<'a> {
}
}
"done-time" => {
let times: Vec<&str> = tokens[1].split("..").collect();
if times.len() > 2 {
return Err(ParseFilterError::ParseError);
}
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);